LoginSignup
gyoumu01
@gyoumu01 (HIEP HOANGDUC)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

金額フォーマット方法

自動計算の金額をフォーマットしたい。

商品の金額フォーマットしたいんですがなかなかですません

<table class="table table-borderless" style="border:1px solid gray;">
                  <thead>
                     <tr>
                        <th  style="border:1px solid gray;" scope="col" colspan="2">商品名</th>
                        <th  style="border:1px solid gray;" scope="col">ケース単価</th>
                        <th  style="border:1px solid gray;" scope="col">ご注文(箱)</th>
                        <th  style="border:1px solid gray;" scope="col">ご注文(個数)</th>
                        <th  style="border:1px solid gray;" scope="col"></th>

                     </tr>
                  </thead>
                  <tbody>
                     <tr>
                        <th scope="row"  style="border:1px solid gray;"> <input class="form-check-input" type="checkbox" name="ProductHGuard" id="ProductHGuard" ></th>
                        <td  style="border:1px solid gray;">H Guard社 インフル&コロナ ダブル検査キット(25個入り)</td>
                        <td  style="border:1px solid gray;">37,500円/箱</td>
                        <td  style="border:1px solid gray;"> <input class="form-control" type="text" name="numberProductHGuard" id="numberProductHGuard" placeholder="2~" onchange="sanpham1()" disabled></td>
                        <td style="border:1px solid gray;"><input class="form-control" type="text" name="numberProductHGuard1" id="numberProductHGuard1" disabled value="0" ></td>
                        <td  style="border:1px solid gray;"><input class="form-control" type="text" name="priceProductHGuard" id="priceProductHGuard" value="0"   ></td>
                     </tr>
                     <script>
                        $('#ProductHGuard').change(function(){


                        if ($('#ProductHGuard').is(':checked') == true){
                        $('#numberProductHGuard').prop('disabled', false);
                        $('#numberProductHGuard1').prop('disabled', false);


                        } else {
                        $('#numberProductHGuard').val('').prop('disabled', true);
                        $('#numberProductHGuard1').prop('disabled', true);
                         $('#numberProductHGuard1').val('');
                        $('#priceProductHGuard').val('');
                        $('#sumprice').val('');


                        }

                        });
                     </script>
                     <tr>
                        <th  style="border:1px solid gray;" scope="row"><input class="form-check-input" type="checkbox" name="ProductDIAsia" id="ProductDIAsia" value=""></th>
                        <td  style="border:1px solid gray;">DIAsia社 口腔内粘膜(唾液)コロナ検査キット(25個入り)</td>
                        <td>23,000円/箱</td>
                        <td  style="border:1px solid gray;"> <input class="form-control" type="text" name="numberProductDIAsia" id="numberProductDIAsia" placeholder="2~" onchange="sanpham2()" disabled></td>
                         <td  style="border:1px solid gray;"> <input class="form-control" type="text" name="numberProductDIAsia2" id="numberProductDIAsia2" value="0" disabled></td>
                        <td  style="border:1px solid gray;"><input class="form-control" type="text" name="priceProductDIAsia" id="priceProductDIAsia" value="0"   ></td>
                     </tr>
                     <script>
                        $('#ProductDIAsia').change(function(){


                        if ($('#ProductDIAsia').is(':checked') == true){
                        $('#numberProductDIAsia').prop('disabled', false);
                        $('#numberProductDIAsia2').prop('disabled', false);

                        } else {
                        $('#numberProductDIAsia').val('').prop('disabled', true);
                        $('#numberProductDIAsia2').val('').prop('disabled', true);

                        $('#priceProductDIAsia').val('');
                        $('#sumprice').val('');


                        }

                        });
                     </script>
                     <tr>
                        <td colspan="5" style="border:1px solid gray;">消費税</td>
                        <td  style="border:1px solid gray;">
                           <p>10% <span style="font-weight:bold">自動計算結果の表示</span></p>
                        </td>
                     </tr>
                     <tr>
                        <td colspan="5">合計</td>
                        <td>
                           <div class="input-group mb-3">
                              <input type="text" class="form-control" id="sumprice"  name="sumprice" >
                              <span class="input-group-text" id="basic-addon1"></span>
                           </div>
                        </td>
                     </tr>
                  </tbody>
               </table>
end

計算のJavascirpt

    function sanpham1(){



                     if(document.getElementById("ProductHGuard").checked){
                         var numberProduct = document.getElementById("numberProductHGuard").value;
                     var priceproduct2= document.getElementById("priceProductDIAsia").value;

                        var result =numberProduct*37500;
                        var newresult = result;
                        var tonggia= (priceproduct2*1.1)+(result*1.1) ;
                        var piceProduct1 = numberProduct*25;
                        var tonggiamoi= parseInt(tonggia);


                         document.getElementById('priceProductHGuard').value = newresult.tolocalstring() ;
                          document.getElementById('sumprice').value = tonggiamoi.tolocalstring()
                          document.getElementById('numberProductHGuard1').value=piceProduct1;


                     }

                  }
                       function sanpham2(){
                     var numberProduct = document.getElementById("numberProductDIAsia").value;
                     var priceproduct1 = document.getElementById("priceProductHGuard").value;

                     if(document.getElementById("ProductDIAsia").checked){
                        var result =numberProduct*23000;
                        var tonggia= (priceproduct1*1.1)+(result*1.1) ;
                        var piceProduct2 = numberProduct*20;
                        var tonggiamoi= tonggia;

                         document.getElementById('priceProductDIAsia').value = result.tolocalstring();
                         document.getElementById('sumprice').value = tonggiamoi.tolocalstring();
                         document.getElementById('numberProductDIAsia2').value=piceProduct2;


                     }

                  }




自分で試したこと

2つ商品合計してあと金額フォーマットの[tolocalString()]で使ってみたけど。
合計してから 合計のところにNaN表示されています。
どうすればいいでしょうか。
皆さん手伝ってもらいませんか?

0

1Answer

以下のように変更するとどうでしょうか?
「tolocalString()」=>「toLocaleString()」

-document.getElementById("priceProductHGuard").value = newresult.tolocalstring();
-document.getElementById("sumprice").value = tonggiamoi.tolocalstring();
+document.getElementById("priceProductHGuard").value = newresult.toLocaleString();
+document.getElementById("sumprice").value = tonggiamoi.toLocaleString();
0

Your answer might help someone💌