Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Javascript The toFixed() Method

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 312
    Comment on it

    Basically toFixed ( ) method is used to cut a number after the decimal upto certain point . Suppose i have a number **i.e 12.345678** and i want this number **upto 2 decimal** places only , then using toFixed method i can cut the number after decimal place like **toFixed(2)** result would be **12.34** .
    Syntax ->

    number.toFixed ( [ fractiondigits ] ) ;
    

    Parameters ->
    number -> It is mandatory , and required a Number Object .
    fractiondigits -> It is optional . and it return the string whose length is fixed . If fractiondigit is not supply then it return default value i.e zero ( 0 ) .
    Example ->

    var num = new Number ( 100 ) ;
    var fix = num.toFixed ( ) ;
    document.write ( fix ) ; //Output -> 100
    var num = new Number ( 100.123 ) ;
    var fix = num.toFixed ( 4 ) ;
    document.write ( fix ) ; //Output -> 100.1230
    

    Error can be of two types in this method i.e
    RangeError -> If fractiondigits range is too small or too large . It means its range should be in between 0 to 20 . It allowed to support larger and smaller value as well .
    TypeError -> If this method is invoked on an object that is not a Number

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: