Reputation: 613
I need to split the balance (decimal value) in to two part.
Like 6678.9999 to
6678 and 9999
So my final array will be value[0] = 6678 and value[1] = 9999
Is it possible in lua with decimal,I can do with string.
Can any one guide for me ?
Upvotes: 1
Views: 1523
Reputation: 122443
Is it possible in lua with decimal,I can do with string.
The problem is, floating point numbers are usually not precise, due to the fact that computers use binary system. For example:
print(6678.9999 % 1)
The output is 0.9998999999998
, not 0.9999
.
So the best way is probably still string manipulation:
string.match(tostring(6678.9999), "([^.]*)%.([^.]*)")
Upvotes: 2