Round to a Specific Decimal Place?


#1

Is it possible to round to a specific decimal place? I’m trying to show a simplified version of high numbers (4,000,000 --> 4M). The millions work fine by dividing by 1M. But, when I try to round the variable, it’ll round too high and show 5M when in reality it’s 4.9M.

*temp shortbudget 0
*temp unit "M"
*if budget >=1000000
    *set shortbudget (budget)/1000000
    *set shortbudget round(shortbudget)
    *set unit "M"

Then the thousands. I want to show them as 900K, 90K, 9K etc, and that works fine with this code:

*if ((budget >=1000) and (budget <=999999))
    *set shortbudget (budget)/1000
    *set shortbudget round(shortbudget)
    *set unit "K"

Until I round and it shows as 1000K instead of 999K. Or 26K instead of 25.9K. Without rounding it shows at 999.999K.
Is there any way around this? Or will I have to make sure you can only have 0s and nothing in between?


#2

What will happen if you don’t use the round() syntax?


#3

A number like 4999999 will turn into 4.999999, which is fine, I just want the last five 9s off the number.


#4

I figured it out!
For the millions:

*temp shortbudget 0
*temp remainder 0
*temp unit "M"
*if budget >=1000000
    *set shortbudget (budget)/100000
    *set remainder (shortbudget modulo 1)
    *set shortbudget (shortbudget-remainder)
    *set shortbudget (shortbudget)/10
    *set unit "M"

For the hundred-thousands:

*if ((budget >=1000) and (budget <=999999))
    *set shortbudget (budget)/1000
    *set remainder (shortbudget modulo 1)
    *set shortbudget (shortbudget-remainder)
    *set unit "K"

Ten-thousands and below:

*if ((budget >=1000) and (budget <=99999))
    *set shortbudget (budget)/100
    *set remainder (shortbudget modulo 1)
    *set shortbudget (shortbudget-remainder)
    *set shortbudget (shortbudget)/10
    *set unit "K"

#5

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the @moderators.