숫자 콤마 찍기? 채택완료
채군
7년 전
조회 4,101
오늘 은 갑자기 날씨도 추워지고,,,
지진도 일러 나고.... 다들 괜찮으세요????
사이트에 계산기 비슷한 프로그램이 필요해서 구글링 하던중
아래 소스를 찾았습니다~
다~ 잘되는데~~
숫자 부분이 천원단위 (1,000)
로 콤마를 찍어서 표기를 하고 싶은데... 구글링을 해봐도 해결이 되지않아서..
도움 요청 드립니다~~~
</p>
<p><script type="text/javascript"></p>
<p> $(function () {
$('.pnm, .subtot, .grdtot').prop('readonly', true);
var $tblrows = $("#tblProducts tbody tr");</p>
<p> $tblrows.each(function (index) {
var $tblrow = $(this);</p>
<p> $tblrow.find('.qty, .price').on('change', function () {</p>
<p> var qty = $tblrow.find("[name=qty]").val();
var price = $tblrow.find("[name=price]").val();
var subTotal = parseInt(qty, 10) * parseFloat(price);</p>
<p> if (!isNaN(subTotal)) {</p>
<p> $tblrow.find('.subtot').val(subTotal.toFixed(0));
var grandTotal = 0;</p>
<p> $(".subtot").each(function () {
var stval = parseFloat($(this).val());
grandTotal += isNaN(stval) ? 0 : stval;
});</p>
<p> $('.grdtot').val(grandTotal.toFixed(0));
}
});
});
});
</script>
</head>
<body></p>
<p> <table id="tblProducts">
<thead>
<tr>
<td>Product</td>
<td>Quantity</td>
<td>Price</td>
<td>Sub-Total</td>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" class="pnm" value="" name="pnm" /></td>
<td><input type="text" class="qty" value="" name="qty"/></td>
<td><input type="text" class="price" value="1" name="price"/></td>
<td><input type="text" class="subtot" value="0" name="subtot"/></td>
</tr>
<tr>
<td><input type="text" class="pnm" value="Product Two" name="pnm" /></td>
<td><input type="text" class="qty" value="" name="qty"/></td>
<td><input type="text" class="price" value="1" name="price"/></td>
<td><input type="text" class="subtot" value="0" name="subtot"/></td>
</tr>
<tr>
<td><input type="text" class="pnm" value="Product Three" name="pnm" /></td>
<td><input type="text" class="qty" value="" name="qty"/></td>
<td><input type="text" class="price" value="1" name="price"/></td>
<td><input type="text" class="subtot" value="0" name="subtot"/></td>
</tr>
<tr>
<td><input type="text" class="pnm" value="Product Four" name="pnm" /></td>
<td><input type="text" class="qty" value="" name="qty"/></td>
<td><input type="text" class="price" value="1" name="price"/></td>
<td><input type="text" class="subtot" value="0" name="subtot"/></td>
</tr>
<tr>
<td><input type="text" class="pnm" value="Product Four" name="pnm" /></td>
<td><input type="text" class="qty" value="" name="qty"/></td>
<td><input type="text" class="price" value="1" name="price"/></td>
<td><input type="text" class="subtot" value="0" name="subtot"/></td>
</tr>
</tbody>
<tfoot>
<tr>
<td></td>
<td></td>
<td></td>
<td><input type="text" class="grdtot" value="" name=""/></td>
</tr>
</tfoot>
</table>
</body>
댓글을 작성하려면 로그인이 필요합니다.
답변 2개
채택된 답변
+20 포인트
7년 전
number_format 사용해보세요. 예를 들어 전체 합계에 적용하고 싶으면 이렇게..
$('.grdtot').val(number_format(grandTotal.toFixed(0)));
로그인 후 평가할 수 있습니다
답변에 대한 댓글 5개
�
채군
7년 전
너무 너무 잘 됩니다~~~~^.^ 감사합니다~~~
�
채군
7년 전
혹시 몰라~ ('.subtot').val(number_format(subTotal.toFixed(0))); 값에 함께 적용을 하니
전체 합계 부분의 계산값 끝에 3자리 값이 사라져 버리는 증상이 생겨 버렸습니다....ㅠ.ㅠ
전체 합계 부분의 계산값 끝에 3자리 값이 사라져 버리는 증상이 생겨 버렸습니다....ㅠ.ㅠ
�
작은별
7년 전
거기는 계산할 땐 콤마를 제거하는 부분을 더 추가해야 할 것 같은데요. 저도 초보라 거기까지는..
�
채군
7년 전
감사합니다~~
�
왈로
7년 전
이걸 어디에 붙여넣어야하는건가요? 완전 개허접 초보라ㅠㅠ
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인