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]
    return (_v[1].."."..sub(_v[2],1,2))

P#105105 2022-01-14 21:48

:: dw817

@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.

P#105107 2022-01-14 21:55
:: Miez

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!

P#105110 2022-01-14 22:09
:: dw817

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.

P#105111 2022-01-14 23:03

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2022-01-23 23:53:38 | 0.039s | Q:14