Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Natural numbers on division?

So if I do 4 / 3, I'm going to get 1.3333333333333 as my answer. How can I make that just be a natural number? It's strange doing things for money calculations and ending up saying stuff like "You have $25.33333333333333". I tried to use modulo 1, hoping it would give me the fractional remainder to just subtract from the original, but no luck.

Comments

  • You have three options Math.round(x), Math.floor(x), or Math.ceil(x).

    Floor always rounds down to the nearest integer, Ceil always rounds up to the nearest integer, and Round rounds up or down to the nearest integer depending on the value.

    Examples:

    Round: <<set $var to Math.round(4/3)>><<print $var>>

    Floor: <<set $var to Math.floor(4/3)>><<print $var>>

    Ceil: <<set $var to Math.ceil(4/3)>><<print $var>>
  • Thank you, that did it.
Sign In or Register to comment.