ArticleDirectory
Requirement Overview
Implementation
Requirement Overview
In some statistical reports, the value range of a certain number is quite large. In order to reduce the total number of digits displayed for a large data, a small data must be displayed with sufficient precision, that is to say, different decimal places are displayed based on the data size, which is similar to the
Import Java.math.bigdecimal;import Java.text.decimalformat;import Java.text.numberformat;public class TestNumber { public static Double num = 3.1015926;public static Double zero = 0.00000;//method One: printing is easiest, always at the end there is a two-bit decimal public static void function 1 () {System.out.println (String.Format ("%.2f", num)); System.out.println (String.Format ("%.2f", Zero));} Method Two: After conversion is a string type publi
(1) PHP retains three decimal places and rounded
The code is as follows
$num = 0.0215489;Echo sprintf ("%.3f", $num); 0.022
(2) PHP keep three decimal digits not rounded
The code is as follows
$num = 0.0215489;Echo substr (sprintf ("%.4f", $num), 0,-1); 0.021
(3) php into a method to
Usually using WPS Mobile version of the table, found that in the statistical data process, in many cases to be rounded to the decimal point two decimal digits. Rounding is not possible with cell formatting. In the WPS mobile version, to automatically round the numbers, you need to use the Round function, which is the formula: Round (number, num_digits), which returns a value that is rounded by the specified
PHP rounded to exact decimal places and rounded up. In php, functions such as sprintf, ceil, floor, and round are used to perform rounding. let's take a look at the specific instance. In this article, we will use php to perform four functions in php to take decimal places: sprintf, ceil, floor, round, and so on. let's
// 1.
System. globalization. numberformatinfo provider = new system. globalization. numberformatinfo (); provider. numberdecimaldigits = intdeclength; // number of decimal places to be set double strcashamt=convert.todouble(this.txt cashamt. text); // convert the value of the Controller to doublethis.txt cashamt. TEXT = strcashamt. tostring ("N", provider); // use the tostring function to format the number
Xcart the number of decimal places by default is 2 bits, sometimes need to change the number of bits as needed; At first, the number of bits in the data type in the database can be changed, and the result is that Xcart is limited in the program, only 2 bits. Then only by changing the way the program to change, because of time jincu, only make simple changes (it is possible to add a variable in general setti
This article takes the retention of two decimal places as an example. If you have other requirements, you can easily change them.
1. Use Java. Text. decimalformat (recommended)
Java. Text. decimalformat df = new java. Text. decimalformat ("#. 00 ");DF. Format (number );Eg:
New decimalformat ("#. 00"). Format (3.1415926) // #. 00 indicates two decimal
1.System. Globalization. NumberFormatInfo provider = new System. Globalization. NumberFormatInfo ();Provider. NumberDecimalDigits = intDecLength; // number of decimal places to be setDouble strCashAmt=Convert.ToDouble(this.txt CashAmt. Text); // convert the value in the control to doubleThis.txt CashAmt. Text = strCashAmt. ToString ("N", provider); // use the ToString function to format
1. system. Globalization. numberformatinfo provider = new system. Globalization. numberformatinfo ();
Provider. numberdecimaldigits = intdeclength; // number of decimal places to be set
Double strcashamt=convert.todouble(this.txt cashamt. Text); // convert the value in the control to double
This.txt cashamt. Text = strcashamt. tostring ("N", provider); // use the tostring function to format
Tags: nbsp div sel Select AST Tools Word Digital key Select cast (362315*1.0/10000 as numeric (18,2)) Select Convert (decimal (2), 362315 * 1.0/10000) 1. ROUND (the function, which is only responsible for rounding to two decimal places, but not responsible for truncating only leaving two decimal
Label:1. ROUND (the function, which is only responsible for rounding to two decimal places, but not responsible for truncating only leaving two decimal places, for example, the following example:)As for the round function, we generally understand that 4 is 5 in, such as:Print ROUND (13.145, 2);The result is: 13.1502. U
This article is about the retention of decimal places in the database on the issue of a detailed analysis of the introduction, the need for friends to refer to the
In the database sometimes we may need to deal with some data, such as rounding, directly to the back of the several, in fact very simple, there are ready-made functions, we just need to apply on the line:Select Round (10.98*10)/10 from dual;--rou
1.system.globalization.numberformatinfo Provider = new System.Globalization.NumberFormatInfo ();Provider. Numberdecimaldigits =intdeclength; Number of decimal places to setDouble strcashamt=convert.todouble (This.txtCashAmt.Text); First, turn the values in the controls into double
This.txtCashAmt.Text = strcashamt.tostring ("N", provider); Using the ToString function to format
05: The output retains 12 decimal places floating point number
Total time limit:
1000ms
Memory Limit:
65536kB
Describe
Reads a double-precision floating-point number, retains 12 decimal places, and outputs the floating-point number.
Input
In javascript, regardless of Single-precision float and double-precision, all decimal variables are regarded as float. Therefore, to obtain the n digits after decimal places, use the toFixed (n) method to obtain
Convert js numbers to float and take N decimal places:
====
The company needs to process some reports and use percentages to keep 2 decimal places. Only the round and trunc functions can be used to implement (round (_ data, 2), but the format is not neat, you can use round if the format is not rigorous.I personally think it is more convenientSelect decode (n_jg, 0, '0. 00', trim (to_char (n_jg, '192. 99') from tblIf it is only for retrieval, use:1. select trunc (CUR
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.