Jump to content




"term.write" adds ".0" for no reason


  • You cannot reply to this topic
2 replies to this topic

#1 TheReduxPL

  • Members
  • 3 posts

Posted 04 August 2014 - 04:20 PM

The issue presents itself really simple.
If I do:
print(reactor.getFuelAmountMax())
I get 160000 which is prefectly fine. But if I use
term.write(reactor.getFuelAmountMax())
I get 160000.0 even though the value returned by reactor.getFuelAmountMax() has no decimal places. Same with every other function that returns a number. Using math.floor() doesn't remove it, and I can't get math.round() to work.
I want a number to have no decimal places, as when using print(). How can I fix that? It's really bothering me.

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 04 August 2014 - 04:35 PM

You've got it backwards. Term.write isn't adding the decimal place, print is removing it. Print does a tostring on all of its arguments before printing them. When integer numbers are tostring'd, the resulting string does not contain any decimal places. Simply use a tostring with your term.write and you should be fine:

term.write(tostring(reactor.getFuelAmountMax()))


#3 TheReduxPL

  • Members
  • 3 posts

Posted 04 August 2014 - 04:46 PM

View PostLyqyd, on 04 August 2014 - 04:35 PM, said:

You've got it backwards. Term.write isn't adding the decimal place, print is removing it. Print does a tostring on all of its arguments before printing them. When integer numbers are tostring'd, the resulting string does not contain any decimal places.
I see now, I will keep it in mind. Thanks for explaining it :)

View PostLyqyd, on 04 August 2014 - 04:35 PM, said:

Simply use a tostring with your term.write and you should be fine:

term.write(tostring(reactor.getFuelAmountMax()))
That actually did the trick, thank you for that as well!





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users