How to make a large floating point number in the database display normally without being displayed in scientific notation

Source: Internet
Author: User
A problem found during my internship was that the large floating point number was removed from the database and then changed to the scientific notation display. However, the original verification control did not recognize the scientific and technical methods, which made the data unable to be properly stored, A solution is found temporarily. When big data is input, the floating point type is displayed in scientific notation when retrieved from the database. For example

A problem found during my internship was that the large floating point number was removed from the database and then changed to the scientific notation display. However, the original verification control did not recognize the scientific and technical methods, which made the data unable to be properly stored, A solution is found temporarily. When big data is input, the floating point type is displayed in scientific notation when retrieved from the database. For example

A problem found during my internship was that the large floating point number was removed from the database and then changed to the scientific notation display. However, the original verification control did not recognize the scientific and technical methods, which made the data unable to be properly stored, A solution is found temporarily.

When big data is input, the floating point type is displayed in scientific notation when retrieved from the database.

For example, when the input is 2222222222, the page is displayed as 2.222222222E9, which cannot be saved during modification.

Solution:

1. method 1

For example, the unit price of a vehicle:

Note that the black part is the display mode of the unit price of vehicles. maxIntegerDigits is the maximum length of the integer part, and maxFractionDigits is the maximum length of the fractional part.

In this way, 2.222222222E9 can be converted to 2,222,222,222 and then removed by string matching. "," the regular expression is used for processing, and the function is

2. method 2

Use regular expressions to process strings and remove the formatted floating point number type.

Function formatNum (id ){

Document. getElementById (id). value = document. getElementById (id). value. replace (/,/gi ,'');

}

This function can remove "," From 2,222,222,222 to display it normally.

The id is the id of the input box.

InAdd the following statement to the onload attribute of to call formatNum ("cldj ");


3. Method 3

The Code is as follows:



<%
Java. text. DecimalFormat df = new java. text. DecimalFormat ("#0.00000"); // specify the conversion format
Object cash = request. getAttribute ("cash ");
If ("". equals (cash) | cash = null) {cash = "0 ";}
String str = df. format (cash); // convert a value of the double type to a value of the String type.
%>
<% = Str %>

4. Method 4

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 the preceding 0 (for example, 000123213, and finally 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 indicates the number you want to convert */
/** 50 indicates the total number of digits to be reserved,
* 2 indicates the number of decimal places,
* If you do not know how many bits are left in total, you can increase the number (for example, 50 here)
* Generally, the total number of digits does not exceed 50 unless the customer needs this.
* Decimals are performed according to customer requirements.
**/
Str = padDoubleLeft (d, 50, 2 );
System. out. println (str );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.