Hi, how can I'm convert 4.93802935 to 4.39...I'm thinking like's strfind(4.93802935,"(%x+.%x)")
More efficient:
function Round(iNumber)
assert(type(iNumber) == "number");
return floor( iNumber + 0.5 );
end
Round is designed to round the first place after the decimal. So you would use:
local myNumber = 4.93802935;
myNumber = Round( mNumber * 100 ) / 100;
Just presenting concept here. Haven't actually tested.
Future functionality questions > http://www.lua.org/manual/4.0/manual.html
-NotRabidWombat
10x u :D
what about:
myNimber = 4.93802935
myNimber = format("%0.2f", myNimber )
u will get 4.93
Yes that will also work. However the return result is a string. I was assuming he wanted rounding rather than truncation.
-NotRabidWombat
local myNumber = 4.93802935
myNumber= format("%0.2f", myNumber)
you will get (and I typed it wrong) 4.94
local myNumber = 4.93328029
myNumber= format("%0.2f", myNumber)
you will get 4.93
and round() is not a Lua interface
Ah cool. Did not know format would handle that.
"and round() is not a Lua interface"
I don't understand your point. It's a function that I just wrote.
-NotRabidWombat