Math function to get first two digits of a float?

There’s a long list of functions for math.
Does anyone know which one gets the first two digits of a float?

Well, you can use string.sub for that. You will have to check specifically for the decimal though. Additionally you can strip the decimal but that would change the value.
print( string.sub( 1.324, 1, 2 ) )

Oh yeah, you’re right.

When you say the first two digits do you mean something like:


if you’re just splitting the numbers before the decimals use string.Split or sub/gsub whatever then tonumber it

probably should read the replys before i post

Or you can do this if instead of using string functions to seperate.

int, frac = math.modf( float )

If you don’t want to use string typecasting you can floor to a specific decimal point.

[lua]local nSrc = 1.11111
local n1 = math.floor( nSrc * 10 ) / 10 – 1.1
local n2 = math.floor( nSrc * 100 ) / 100 – 1.11
local n3 = math.floor( nSrc * 1000 ) / 1000 – 1.111

Thanks to all of you.