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

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

Started by TheReduxPL, 04 August 2014 - 03:20 PM
TheReduxPL #1
Posted 04 August 2014 - 05: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.
Lyqyd #2
Posted 04 August 2014 - 05: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()))
TheReduxPL #3
Posted 04 August 2014 - 05:46 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.
I see now, I will keep it in mind. Thanks for explaining it :)/>

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!