JS reserved 2-bit decimal rounding (less than 2 digits after the decimal point, self-use 0-padded)

Source: Internet
Author: User
function Changetwodecimal_f (x) {
var f_x = parsefloat (x);
if (IsNaN (f_x)) {
Alert (' Function:changetwodecimal->parameter error ');
return false;
}
var f_x = math.round (x * 100)/100;
var s_x = f_x.tostring ();
var pos_decimal = S_x.indexof ('. ');
if (Pos_decimal < 0) {
Pos_decimal = S_x.length;
S_x + = '. ';
}
while (s_x.length <= Pos_decimal + 2) {
s_x + = ' 0 ';
}
return s_x;
}

Reference Link: http://www.jb51.net/article/45884.htm

JS reserved 2-bit decimal rounding (less than 2 digits after the decimal point, self-use 0-padded)

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.