JS reserved two decimal places multi-decimal (JavaScript)

Source: Internet
Author: User
Tags pow

<script language= "Javascript" >
<!--
function Formatfloat (SRC, POS)
{
Return Math.Round (Src*math.pow (), POS)/math.pow (POS);
}
Alert (Formatfloat ("1212.2323", 2));
-
</SCRIPT>
There are several ways to do this:
var test=11111.111;
Alert (test.tofixed (2));
float data rounded to 2 decimal places;


function To2bits (FLT) {
if (parsefloat (flt) = = FLT)
Return Math.Round (FLT * 100)/100;
to 4 decimal places, return Math.Round (FLT * 10000)/10000;
Else
return 0;
}

ASP retains two decimal places
<%=formatnumber ( -888.888,3,-1,-1,0)%>
(888.900)
The example uses all the parameters of the function FormatNumber ():
The first parameter (-6665.8999) specifies the number to be formatted.
The second parameter (3) specifies the number of digits to display after the decimal point.
The third parameter (-1) specifies whether the leading 0 is displayed.
The fourth parameter (-1) Specifies whether parentheses are used for negative numbers.
The last parameter (0) specifies whether to display separators

JS reserved two decimal places multi-decimal (JavaScript)

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.