Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: mokoHi,
I have a question about converting from a string to a double in order to perform a rounding operation, and then converting back to a string for comparing with another decimal field. If I have a value like 1.123456789 and convert it to a double and round it to eight decimal places, I get 1.12345679, as expected. If I think convert it back to a string, I get 1.12346. If I use the format function, it�s rounded to six decimal places, 1.123457. Is there a way I can convert back to a string without any further rounding occurring? Here is the code I�m using, and the output I get. Thanks.
a = "1.123456789"
b = a.double().round(-8)
c = b.str()
d = format("%f",b)
emit a as "a", b as "b", c as "c", d as "d"
a
string |
b
double |
c
string |
d
string |
| 1.123456789 |
1.12345679 |
1.12346 |
1.123457 |