admin管理员组文章数量:1302438
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 is 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 acplish this? Or does anyone know of a better way?
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 is 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 acplish this? Or does anyone know of a better way?
Share asked Sep 15, 2011 at 20:19 Rob_IGSRob_IGS 5753 gold badges8 silver badges17 bronze badges1 Answer
Reset to default 10You 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
本文标签: javascriptRounding a number up to get no decimalStack Overflow
版权声明:本文标题:javascript - Rounding a number up to get no decimal - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741716311a2394130.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论