Javascript--toFixed () function

Source: Internet
Author: User

Javascript--toFixed () function

1. toFixed (n) limit the number of digits after the decimal point, rounded. N:0~20.

2. The action object must be number and cannot be a different type. such as (8.001). toFixed (2) return to 8.00;

3. ToFixed (n) the return value is of type string, and it is wrong to make the size as a number.

4. Parsefloat ("number") and parseint ("numbers") read the first encounter in the string (for example, 91.2w3 the first number is 91.2) and convert to a float or int, the return type is #.

Grammar

Parsefloat () Converts a string to a floating-point number

The ToFixed () method rounds numbers to a number that specifies the number of decimal digits

Parameters

The parsefloat () parameter is the string to be converted

ToFixed () Specifies the number of decimal places, which are values between 0 and 20, including 0 and 20, and some implementations can support a larger range of values. If this argument is omitted, 0 is used instead

return value

Converted Numbers

1<!DOCTYPE HTML>2<HTML>3<Scriptsrc= "Http://code.jquery.com/jquery-latest.js"></Script>4<Head>5<MetaCharSet= "Utf-8">6<title>ToFixed ()</title>7</Head>8<Body>9</Body>Ten<Scripttype= "Text/javascript"> One   varA0= 8.01. toFixed () A   varA1=parsefloat ("8.006"). toFixed (2); -   varA2=parsefloat ("9.091"). toFixed (2); -document.write ("A0 Type:"+typeof(A0)+"<br>"); thedocument.write ("A1 Type:"+typeof(A1)+"<br>"); -document.write ("A2 Type:"+typeof(A2)+"<br>"); -document.write ("A0:"+A0+"<br>"); -document.write ("A1:"+A1+"<br>"); +document.write ("A2:"+A2+"<br>"); -document.write ("A1 is less than A2?:" +(A1<A2)+ "<br>"); + </Script> A</HTML>

Javascript--toFixed () function

Related Article

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.