簡単な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>