2012-11-30 4 views
7

次のコードがあります。美しく離れて私はjqueryの最終出力を切り上げます

$(document).ready(function(){ 

// Animate logo 
$('#Logo').hide().fadeIn(800); 

// Calculation Scripts 
// Square Metres 
var output = $('#SquareMetres'), 
    tinoutput = $('#Tins'), 
    priceoutput = $('#Price'); 
$('input[type="text"]').keyup(function() { 
var width = parseFloat($('#width').val()), 
    height = parseFloat($('#height').val()), 
    result = height * width/10000, 
    finalresult = result.toFixed(2); 
if (isNaN(result)) return; 

output.text(finalresult); 

// Tins 
var tinmetres = 32.5, 
    tinprice = 18.23, 
    tinsresult = finalresult/tinmetres; 
    tinstotal = tinsresult.toFixed(2); 

tinoutput.text(tinstotal); 

var price = tinstotal * tinprice, 
    totalprice = price.toFixed(2); 

priceoutput.text('£'+totalprice) 

}); 
}); 

スクリプト(3などに切り上げされている2.04)最終tinstotal変数が最も近い1に切り上げさせたいから作品底部付近に赤いボックスにhttp://andyholmes.me/sitewizard/index.htmlでここに有効です。皆さん、助けてくれることを祈っています。ありがとう!

答えて

25
tinstotal = Math.ceil(tinsresult); 
tinoutput.text(tinstotal); 

Math.ceil()を探している想像次の整数

+0

既にMath.Ceil()を使用していますので、.toFixed(2)を使用する点はありません。 –

1

使用に丸めますjavascript Math.round()

ex: 
var a = Math.round(2.60); 
var b = Math.round(-2.60); 
var c = Math.round(2.49); 

Result : 
alert(a); => 3 
alert(b); => -3 
alert(c); => 2 

希望はあなたを助けます。

関連する問題