숫자 3자리수 자동콤마

숫자 3자리수 자동콤마

QA

숫자 3자리수 자동콤마

본문

안녕하세요 질문좀 드리겠습니다.

 

아래 소스코드내에서 

 

opt_price / stotal

 

위두개가 숫자로만 이루어져 있는데 글을쓸때도 자동으로 3자릿수 콤마 되게끔 하는방법이있을까요?

구글링을 해봐도

 

opt_price 는 적용이 안되고 

stotal 는 콤마가 풀리는 현상이 나오더라구요 ㅜ

 

부탁좀 드리겠습니다.

 


<!-- 반복 -->
            <tr>
                <td class="td_num">
                    <label for="ct_qty_<?php echo $chk_cnt; ?>" class="sound_only" value="<?php echo $opt['ct_qty']; ?>"> 수량</label>
                    <span class="quantity"><?php echo $opt['ct_qty']; ?></span>
                </td>
                <td class="td_num_right "><input type="text" name="opt_price" class="price" value="<?php echo $opt_price ?>"> </td>
                <td class="td_num_right"><span class="calc_price"><?php echo number_format($ct_price['stotal']); ?></span></td>
            </tr>
<!-- /반복 -->
<script>
// 반복되는 부분 말고, 한번만 출력되면 OKAY
$('.price').on('keyup', function() {
    var quantity = parseInt($(this).closest('tr').find('.quantity').text().replace(/[^\d]+/g, '')) | 0;
    var price = parseInt($(this).val().replace(/[^\d]+/g, '')) | 0;
    $(this).closest('tr').find('.calc_price').text(quantity*price);
});
</script>

이 질문에 댓글 쓰기 :

답변 2

+ Intl.NumberFormat

- [영] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat

- [한] https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat

짧은 코드니까, 어떤 명령이 어떤 역할을 하는지 이해 후에 응용&활용하면 되겠습니다.


    <td class="td_num_right "><input type="text" name="opt_price" class="price" value="<?php echo number_format($opt_price); ?>"> </td>
    :
    $(this).closest('tr').find('.calc_price').text(new Intl.NumberFormat().format(quantity*price));
답변을 작성하시기 전에 로그인 해주세요.
전체 2,026
QA 내용 검색
filter #css ×

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT