Page 1 of 1
Rounding the value of levels.
Posted: Mon Apr 05, 2010 2:14 am
by YahyaRafique
Hey guys
Is there a way of rounding the value of levels to for example 2 decimal places?
Regards,
YR
Posted: Mon Apr 05, 2010 8:21 am
by LAUJJL
use level = INT(-level + (integer((level + 0.5) * 100) / 100) )
Posted: Mon Apr 05, 2010 9:20 am
by bob@vensim.com
If your question is about display use %.2f as the format for the table tool or custom tables/reports. If you are asking about computation then something similar to what JJ such as
rounded level = INTEGER(level * 100.0 + 0.5)/100.0
should work, though I can't think of a case where this would be very helpful.
Posted: Mon Apr 05, 2010 3:50 pm
by tomfid
If you're using Vensim DSS, it's handy to put JJ's formula in a macro, like
:MACRO: ROUND(x,digits)
ROUND = INTEGER(x*10^digits+0.5)/10^digits
~ x
~ |
:END OF MACRO:
a test:
digits=
1
~ [-2,2,1]
~ |
test x=
ROUND(453.123,digits)
~
~ |
Note that precision is also limited by the floating point format.