Log In  


Tiny function that takes a number (float or int) and returns a string with (maximum) two decimals. For instance:

10 > "10"
20.03 > "20.03"
17.46134 > "17.46"

So not mathematically accurate, but useful under some circumstances...

function twodecimal(_n)
  -- will accept a number (float or int)
  -- turn it into a string and return the string with two decimals

  local _v=split(tostring(_n),".")
  if #_v==1 then
    return _v[1]
  else
    return (_v[1].."."..sub(_v[2],1,2))
  end

end
1


@Miez, that's an interesting way of doing INSTR() using SPLIT() like that.

You might be interested in a program I wrote some time ago to calculate very big numbers.

It's call BIG INTEGERS and you can search for it if you like.


Nice! Thanks for the tip. Right now the use of big numbers in my little project is very limited, but I will keep your library in mind!


Very good, @Miez. And oh yes you did teach me something I didn't know. A way to emulate INSTR() through SPLIT() without using FOR/END. Gold star for you.



[Please log in to post a comment]