Rounding a number up to get no decimal
I am writing a script (in J Script) that takes the pressure of Oil in a pump, and displays it on a digital display.
The problem is that the Pump outputs the pressure level in Pascals, while the digital display 开发者_如何学Gois intended to display in PSI (the number of digits on the display is limited to 4, and the pressure levels of the oil in the pump in pascals is like 15 digits.)
Currently the script is simple :
var Pump1_Digi : Demo3D.Visuals.BoxVisual = sender.FindChild("Pump1_Oil_Pressure_Digi");
Pump1_Digi.Pressure_Num = sender.Pump1_Oil_Pressure;
Pump1_Digi.PropertiesUpdated;
Pump1_Digi.Pressure_Num is the value I write to that is displayed on the digital display.
sender.Pump1_Oil_Pressure is the acutal value of the oil pressure in pascals.
I know that 6894.757 Pascals is 1 PSI
so I can do this:
var Pump1_Digi : Demo3D.Visuals.BoxVisual = sender.FindChild("Pump1_Oil_Pressure_Digi");
var Pump1toPSI : Pressure;
sender.Pump1_Oil_Pressure / 6894.757 = Pump1toPSI;
Pump1_Digi.Pressure_Num = Pump1toPSI
Pump1_Digi.PropertiesUpdated;
While my result is now in PSI, the numbers after the decimal point go on nearly for ever.
What I would like to do is just round the result to the nearest whole number.
Is there a parse function in Jscript to accomplish this? Or does anyone know of a better way?
You want the Math.ceil()
function to round up to the nearest integer. Or Math.round()
to round up or down as necessary:
Math.ceil(1.2098344305985700003482);
// 2
Math.round(1.2098344305985700003482);
// 1
精彩评论