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!?!
Announcement
Collapse
No announcement yet.
Precision of return() items
Collapse
X
-
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(value, decimals ) {
value = value * Math.pow(10, decimals);
return Math.round(value, decimals) / Math.pow(10, decimals);
}
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