Fairmath rounding


#1

I understand how Fairmath operates, and I know that there are separate rounding commands which you can use if desired. I’m struggling to find any documentation on how Fairmath treats fractional results in the absence of a specific rounding instruction.

Suppose I want to fairadd 5% to 47. If I’m doing my sums correctly, that gives a result of precisely 49.65. In the absence of explicit rounding commands, how will Choicescript round? Some posts seem to think that fairadds always round down (and vice versa), and others that it will round to the nearest whole number. Can anyone shed any light?


#2

I believe that it rounds to the nearest whole number. (Don’t quote me on this) I hope you find a quick answer to your question! If I can be of any help, just mention me in a reply! :smile:


#3

Here’s the IDE. Great for testing things.

https://dl.dropboxusercontent.com/u/7840892/CJW/choicescript/tools/IDE/main.html#

I typed in

*create value 47
*set value %+ 5
${value}

The answer it gives is 49. So looks like it rounds down.


#4

To expand on that, I’m fairly sure part of the reason for it rounding down is to prevent it reaching 100. I haven’t tested it in a long while, but Fairmath caps at 1 and 99.


#5

If you want to see Fairmath in action, here’s the calculator I built.


#6

Blast - Reaperoa’s explanation makes sense as to the why, it’s just not the answer I was hoping for.

Thanks for the help, everyone.


#7

Is there a particular problem you’re having because of fairmath’s rounding? or is it s more general you were hoping it worked a different way?


#8

Not a coding problem - merely a min-maxing one. Back to the drawing board…