亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在Javascript/蟒蛇/詹戈中為數字添加千位分隔符

如何在Javascript/蟒蛇/詹戈中為數字添加千位分隔符

慕姐8265434 2022-09-29 17:02:47
我想問一下,當我鍵入數字和輸出時,如何將千位分隔符添加到數字中。例如,10 000 變為 10,000。我試圖使用詹戈內聯逗號,但它不起作用。如果你們能幫助我,真的非常感謝。以下是我的代碼:斷續器<html><head>  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script></head><body>  <div class="container">    <br />    <br />    <div class="form-group">      <form name="add_price" id="add_price">        <div class="table-responsive">          <table class="table table-bordered" id="price">            {{ priceformset.management_form }}            {% for price in priceformset %}             <tr>              <td>{{ product.product_price }}</td>              <td>{{ product.product_quantity }}</td>              <td>{{ product.product_total_price }}</td>            </tr>            {% endfor %}          </table>          <input type="button" name="submit" id="submit" class="btn btn-info" value="Submit" />        </div>      </form>    </div>  </div></body腳本$('.textInput').on('change keyup', function() {      product_total_price=0;      var product_price= Number($('#id_Product-0-price').val());      var product_quantity= Number($('#id_Product-0-quantity').val());      product_total_price= product_price * product_quantity;      $('#id_Product-0-total_price').val(product_total_price);});Models.py class Price (models.Model):    product_price = models.CharField(max_length=512,null=True,blank=True)    product_quantity = models.CharField(max_length=512,null=True,blank=True)    product_total_price= models.CharField(max_length=512,null=True,blank=True)Forms.pyclass PriceForm(forms.ModelForm):product_price =forms.CharField(required=False,label=('Price'),widget=forms.TextInput(        attrs= {        "class":"textInput form-control",        "placeholder" : "Price"}))
查看完整描述

3 回答

?
aluckdog

TA貢獻1847條經驗 獲得超7個贊

這在js中很容易做到:


let number = 1000

number.toLocaleString()

這是在python中如何做到這一點:


def place_value(number): 

    return ("{:,}".format(number)) 


print(place_value(1000000)) 

樂于幫助


查看完整回答
反對 回復 2022-09-29
?
繁星點點滴滴

TA貢獻1803條經驗 獲得超3個贊

腳本:


const n = 100000

const formated = n.toLocaleString()

蟒蛇(需要蟒蛇3.6+):


n = 1000000

formatted = f'{n:,}'


查看完整回答
反對 回復 2022-09-29
?
慕田峪7331174

TA貢獻1828條經驗 獲得超13個贊

它也適用于浮子式淡水河谷。這有點復雜,但我真的很喜歡分享我的想法。它基于腳本。

value.toString().split('.').map((v, i) => i===0?v.split('').map((val, idx, self) => ((idx===0)||((self.length-idx)%3!==0))?val:`,${val}`).join(''):v).join('.')


查看完整回答
反對 回復 2022-09-29
  • 3 回答
  • 0 關注
  • 160 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號