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

alot of unnessecary numbers on the monitor.

Started by Dustmuz, 11 October 2014 - 10:24 AM
Dustmuz #1
Posted 11 October 2014 - 12:24 PM
Hello again..

i would like to know, if it is possible to "get rid of" all the extra numbers that comes after the punktuation in a number..

more specificly.. the Big reactor heat.

pastebin

mon = peripheral.wrap("monitor_0")
rea = peripheral.wrap("back")

mon.setCursorPos(1,1)
mon.write("Reactor 1:")

local function fuel()
  fuelam = rea.getFuelAmount()
  fuelmax = rea.getFuelAmountMax()
  return math.floor(fuelam / fuelmax * 100)
end

while true do
cheat = rea.getCasingTemperature()
fheat = rea.getFuelTemperature()

mon.setCursorPos(1,3)
mon.clearLine()
mon.write(fheat)

mon.setCursorPos(1,4)
mon.clearLine()
mon.write(cheat)

mon.setCursorPos(1,5)
mon.clearLine()
mon.write(fuel())
sleep(1)
end
Edited on 16 December 2014 - 02:26 AM
Dragon53535 #2
Posted 11 October 2014 - 01:20 PM
You're using it in your fuel function. math.floor()
InputUsername #3
Posted 11 October 2014 - 01:26 PM
Another option would be:

local function round(n)
    return math.floor(n + 0.5)
end
wieselkatze #4
Posted 11 October 2014 - 01:39 PM
If you also want to get rid of the '.0' at the end of your numbers, you could use tostring() and build e.g. the following function:


function formatNumber( num )
  return tostring( math.floor( num ) )
end

with this you could replace

mon.write( fheat )
with

mon.write( formatNumber( fheat ) )