Jump to content




Printing float digits...


  • You cannot reply to this topic
1 reply to this topic

#1 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

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 by LeDark Lua, 09 December 2018 - 08:00 PM.


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users