Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exponential to Number.

    Hi All,

    I have a problem in javascript.

    When i am doing rounding of the value i am getting the o/p like 2.2e4.

    I have to display this value in decimal value(2.0002) not in exponential.

    Can any one please help me to resolve this issue.?

    Regards,
    VIjai

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    Um...you apparently don't understand what 2.2e4 means.

    2.2e4 is the same as 22000.0

    2.2e-4 would be the same as 0.00022

    I'm actually surprised that you would ever get "2.2e4". Are you sure it wasn't "2.2e-4"???

    Anyway, you *can* control the display using toFixed( n ) where n is the number of digits to be shown after the decimal point.

    So:
    Code:
    var num = 2.2e4;
    alert( num.toFixed(2) ); // would show 22000.00
    var num = 2.2e-4;
    alert( num.toFixed(2) ); // would show 0.00 -- because the 0.00022 "rounds" to just 0.00
    var num = 2.2e-4;
    alert( num.toFixed(6) ); // would show 0.000220
    And so on.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •