Mark Mark - 1 month ago 7x
Javascript Question

Numeric Textbox - Formatting

I have a disabled textbox that shows a calculated percentage.
I am looking to format this text box to always show a single decimal place, even if the number is a whole number.

I feel like this should be simple, but for some reason I can't figure this out.

Any suggestions?

<div class="labelReallySmall">
@Html.Label("%F", null, new { @class = "req" })
@Html.TextBox("PFat305", null, new { disabled = true })
$(document).ready(function () {
$("#305Fat").change(function () {
var a = parseInt($(this).val());
var b = parseInt($("#Milk305").val());
var c = (a*100)/b ;

Thanks in advance, Mark


Try .toFixed(n) - where n - is number of decimals.