Announcement

Collapse
No announcement yet.

Precision of return() items

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Precision of return() items

    How can I control the precision of return() data? If I want only whole numbers, I've tried Math.round() but I still get two decimal places. How can I get three decimals? Also, if I want dollars/cents I get 123.1, 123.2 instead of 123.10, 123.20, etc. In the good old COBOL days we had "PICTURE"; seems to me I've stumbled over the appropriate construct in the past, but can't locate the syntax currently. Help!?!

  • #2
    IrvPrail
    At this time you cannot increase the precision beyond what the formula engine will determine.
    You can however reduce the precision through a simple function such as the following
    PHP Code:
    function rnd(valuedecimals ) {  
        
    value =  value Math.pow(10decimals);
        return 
    Math.round(valuedecimals) / Math.pow(10decimals);

    In your main function you would then call the rnd() function specifying the value and the number of decimals eg
    var myVar = rnd(1.2345, 2) which will return 1.23
    Alternatively if you want to return only the integer portion you could use the parseInt() function
    Alex

    Comment


    • #3
      Alex: As always:, a prompt, accurate and concise answer. Thank you, thank you, thank you! You indeed continue to save our bacon, seemingly without breaking a sweat. Kudos!!

      Comment


      • #4
        IrvPrail
        As always you are most welcome and thank you very much for the kudos
        Alex

        Comment

        Working...
        X