0

In Lua how can I reliably get real world results to arithmetic:

local result = (1.09891 - 1.09889);
print(result);

the result i get is
2.0000000000131e-05


real result i want
.00002
deChristo
  • 1,860
  • 2
  • 17
  • 29
shobuz
  • 11
  • 1
  • 1
  • 4

1 Answers1

1

There is nothing wrong with the result value. See this question and answer for why the result is not exactly what you think it should be. But, if all you are worried about is how it looks when you print it to the screen, you can do things like:

print(string.format('%f', result))
0.000020

print(string.format('%.5f', result))
0.00002

to format the printing of the result to your liking.

See here for more info on string.format, or wikipedia for an explanation of the 2e-5 value if you're unfamiliar with scientific notation.

Community
  • 1
  • 1
mshildt
  • 8,782
  • 3
  • 34
  • 41