Rounding the value of levels.

Use this forum to post Vensim related questions.
Post Reply
YahyaRafique
Junior Member
Posts: 13
Joined: Mon Mar 29, 2010 4:28 am

Rounding the value of levels.

Post by YahyaRafique »

Hey guys

Is there a way of rounding the value of levels to for example 2 decimal places?

Regards,

YR
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Post by LAUJJL »

use level = INT(-level + (integer((level + 0.5) * 100) / 100) )
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post 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.
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Post 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.
Post Reply