This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LeDark Lua's profile picture

Printing float digits...

Started by LeDark Lua, 09 December 2018 - 06:58 PM
LeDark Lua #1
Posted 09 December 2018 - 07:58 PM
Hey all, so I'm stuck with a question, how to print float number digits, without stringifying it, only using math… and telling at which position the dot went
Input: 3.14
Output: 3, (dot here), 1, 4

I know how to get all digits in an integer:

local i = 0
local num = 12345
while num >= 1 do
    print( num % 10 )
    num = math.floor( num / 10 )
    i = i + 1
end
print( "Number of digits: " .. i )


HELWP! Thanks…
Edited on 09 December 2018 - 07:00 PM
KingofGamesYami #2
Posted 09 December 2018 - 09:50 PM
Think about what num % 1 would return if there is no decimal. You can come up with a simlple program similar to the one you have now with that information.