我有一个带有一些简单 JavaScript 的表单来执行即时计算。我的问题是我正在努力格式化它以使用逗号和 2 个小数位正确显示。
任何帮助将不胜感激。谢谢你。
<p>
<label>My Daily Rate is:</label><br />
<input class="poundsBox" name="shares" id="shares" type="text" /><br />
<br />
<strong>Your Gross Contract Take Home:</strong></p>
<p><span class="result">£ <span id="result"></span></span></p>
The above illustration is provided for guidance only. Please complete the request form below for a detailed personal illustration.
<script type="text/javascript">
$("#shares").keyup(function() {
var val = parseFloat($(this).val());
// If val is a good float, multiply by 260, else show an error
val = (val ? val * 260 * 0.88 : "Invalid number");
$("#result").text(val);
})
</script>