簡體   English   中英

在JavaScript中將數字格式設置為貨幣字符串?

[英]Format numbers as money string in javascript?

我想用JavaScript格式化價格。

-> 250012

它應該是

-> 2.500,12

視圖

 <div class="form-group">
        @Html.LabelFor(model => model.Price, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Price, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Price, "", new { @class = "text-danger" })
        </div>
    </div>
> const number = 250012;
> (number/100).toLocaleString('de-DE')
< "2.500,12"

有關瀏覽器支持和更多信息,請參見https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM