guenther
06/27/2019, 3:24 PMDouble (12.456778)
to a certain precision. This would be something really useful like
12.34567.roundToPrecision(...)
(don't nail me on the function name, I'd just want to express that rounding would be useful. What do you think?karelpeeters
06/27/2019, 3:28 PM0.3
simply isn't representable as a floating point number.pavel
06/27/2019, 3:29 PMkarelpeeters
06/27/2019, 3:29 PMkarelpeeters
06/27/2019, 3:29 PMguenther
06/27/2019, 3:42 PMFloat -> String -> Float
karelpeeters
06/27/2019, 3:43 PMFloat -> String -> Float
is wrong!karelpeeters
06/27/2019, 3:44 PMguenther
06/27/2019, 3:53 PMkarelpeeters
06/27/2019, 3:53 PMBigDecimal
instead.pavel
06/27/2019, 3:54 PMDouble
is good enoughkarelpeeters
06/27/2019, 3:55 PMpavel
06/27/2019, 3:56 PMelizarov
06/27/2019, 9:30 PM.toString()
prints at most two digits) then just write: round(x * 100) / 100
.elizarov
06/27/2019, 9:31 PMelizarov
06/27/2019, 9:32 PMHullaballoonatic
06/27/2019, 9:33 PM1f + 2f
isn't 1f+2f == 3.00000000000000000000000001
or something?elizarov
06/27/2019, 9:34 PMHullaballoonatic
06/27/2019, 9:34 PMelizarov
06/27/2019, 9:34 PMHullaballoonatic
06/27/2019, 9:35 PMHullaballoonatic
06/27/2019, 9:36 PMHullaballoonatic
06/27/2019, 9:36 PMabs(b - a) < epsilon
elizarov
06/27/2019, 9:36 PMHullaballoonatic
06/27/2019, 9:37 PMelizarov
06/27/2019, 9:37 PMelizarov
06/27/2019, 9:38 PMHullaballoonatic
06/27/2019, 9:38 PMHullaballoonatic
06/27/2019, 9:38 PMkarelpeeters
06/27/2019, 9:39 PM0.3
but that's a feature of Java string formatting, and it's not actually 0.3
. That what the dogma is about. Of course if you remember to round after every operation and you're dealing with nice numbers it doesn't matter, but it's about the edge cases that always tend to show up.Hullaballoonatic
06/27/2019, 9:41 PMHullaballoonatic
06/27/2019, 9:42 PM