Closed CodyNinja1 closed 1 month ago
You can like this: float y = Math::Round(x * 100.0) * 0.01;
Maybe personal opinion, but I think Math::Round
is often not the right thing to use anyway. It should only be used if you're then using the rounded value for subsequent logic.
Text::Format
should be used in all other cases, e.g. Text::Format("%#3.1f%%", progressPercentage)
Does the format solution work for your use case, @CodyNinja1?
Maybe personal opinion, but I think
Math::Round
is often not the right thing to use anyway. It should only be used if you're then using the rounded value for subsequent logic.
I am using it to perform mathematical operations on the rounded number
Does the format solution work for your use case, @CodyNinja1?
I could use the format solution to convert the float to string with format, and then back to float but that feels clunky.
I also could use XertroV's solution of adding extra zeros and removing them from the float after rounding, but I it would be prefered if that functionality was built into Math::Round
I see - what's your use case specifically? I'm not against this, by the way. Just wondering!
Working with floats can be a challenge sometimes, and a good way of removing float imprecision is rounding by 2 or 3 digits.
How do you figure that?
I'd guess most (mathematically literate) people would agree that rounding introduces imprecision.
a good way of removing float imprecision is rounding by 2 or 3 digits.
Like Xertrov says, I don't think this is true. But then again, I don't know your use-case.
Currently, you can't (for example) use
Math::Round(float)
to round a number to only 2 decimal spaces, or any number for that matter.Example of how to fix this: