Internship in the company found a problem, that is, large floating point number from the database into a scientific counting method, and the original validation control does not recognize the science and technology, resulting in data can not be stored normally, temporary found a solution.
When you enter large data, floating-point types are displayed in the form of scientific notation when they are taken out of the database.
For example, input: 2,222,222,222 echo when the page is displayed as: 2.222222222E9 this can not be stored normally in the modification.
Solution:
1. Method One
In this case, the Jstl Fmt:format label is used for processing,
For example, vehicle price: <input maxlength= "8" type= "text" id= "Cldj" onkeyup= "return Enterinputfocus" (This, event) "input_must=" true " Name= "CLDJ" class= "must Double2" style= "width:100%" value= "<fmt:formatnumber value=" ${jyjycljbxxvo.cldj " maxintegerdigits= "maxfractiondigits=" "/> '/>
Note that the boldface part is the vehicle unit price display, maxintegerdigits is the maximum length shown in the integer section, and the maxfractiondigits is the maximum length shown by the decimal part.
This can be converted to 2.222222222E9 to 2,222,222,222 after the use of string matching to remove the ",", using regular expression processing, the function is
2. Method II
Handle strings with regular expressions, removing formatted floating-point number types
function Formatnum (ID) {
document.getElementById (ID). Value=document.getelementbyid (ID). Value.replace (/,/gi, ");
}
This function can remove the "," in 2,222,222,222 to make it appear correctly.
Where ID is the ID of the input box.
Add the following statement to the <body> onload attribute to invoke Formatnum ("Cldj");
3. Method Three
The code is as follows
<span>
<c:set value= "${raffle.probability}" var= "Cash" scope= "request" ></c:set>
<%
Java.text.DecimalFormat df=new Java.text.DecimalFormat ("#0.00000");//Specify the format of the transformation
Object Cash=request.getattribute ("cash");
if ("". Equals (Cash) | | Cash==null) {cash= "0";}
String Str=df.format (cash);//Convert Double value to string type
%>
<%=str%>
</span>
4. Method Four
Import Java.text.DecimalFormat;
public class Tetr
{
public static String Paddoubleleft (Double d, int totaldigit,int fractionaldigit) {
String str= "";
DecimalFormat DecimalFormat = new DecimalFormat ();
Decimalformat.setminimumfractiondigits (Fractionaldigit);
Decimalformat.setmaximumfractiondigits (Fractionaldigit);
Decimalformat.setgroupingused (FALSE);
Decimalformat.setmaximumintegerdigits (totaldigit-fractionaldigit-1);
Decimalformat.setminimumintegerdigits (totaldigit-fractionaldigit-1);
Str=decimalformat.format (d);
/**
* Remove front 0 (e.g. 000123213, final output 123213)
*/
while (Str.startswith ("0"))
{
Str=str.substring (1);
}
return str;
}
public static void Main (string[] args)
{
String str= "";
Double d=1.7949e+7;
/**d says the number you want to convert
/**50 indicates the total number of digits to be retained,
* 2 means decimal digits,
* If you do not know how many places to stay, you can give a larger (for example, here is 50)
* Under normal circumstances, the total number of digits will not exceed 50 unless the customer has this need
* Decimal in accordance with customer requirements to do
* */
Str=paddoubleleft (d,50, 2);
System.out.println (str);
}
}