Kendo 数字文本框带前缀的货币格式

huangapple go评论148阅读模式
英文:

Kendo numeric textbox currency format with prefix

问题

我正在尝试在Kendo数值文本框中以美元形式格式化数字,但我想在结果字符串之前添加国家代码(US$123.45),以使其与其他以美元为基础的货币区分开来。

Kendo的.format函数提供了我需要的输出:

kendo.format("US{0:c2}", 123.45) // US$123.45

但.toString函数不以同样的方式工作:

kendo.toString(123.45, "US{0:c2}", "en-US") // US{123.45:c2}

这与我在尝试将"US{0:c2}"作为格式属性的值传递给小部件时获得的输出相同。

在查阅了Kendo的文档、Stack Overflow帖子等之后,我仍然苦于找不到其他方法来解决这个问题。

英文:

I am trying to format a number in a Kendo numeric textbox in USD, but I would like to prepend the country code to the resultant string (US$123.45) to allow it to be distinguishable from other dollar-based currencies.

Kendo's .format function provides me with the output that I am after:

kendo.format("US{0:c2}", 123.45) // US$123.45

But the .toString function does not behave the same way:

kendo.toString(123.45, "US{0:c2}", "en-US") // US{123.45:c2}

Which is the same output I am getting in the widget when trying to pass "US{0:c2}" as the value for the format property.

Struggling to find any other way to do this after looking through kendo's docs, SO posts, etc.

答案1

得分: 1

我不确定是否与您的需求完全吻合,因为您的问题缺乏上下文和数字文本框配置的示例代码,但我会尝试提供一些帮助。

您可以在数字文本框上使用自定义数字格式来实现您想要的效果,如下所示:

$("#numerictextbox").kendoNumericTextBox({
    format: "US$0.00",
});

在Kendo Dojo中有一个示例

英文:

I'm not 100% if this lines up with what you need due to lack of context in your question and no sample code for your numeric textbox config, but I'm going to give it a try.

You can use a custom number format on your numeric textbox to achieve what you want like so:

$("#numerictextbox").kendoNumericTextBox({
    format: "US$0.00",
});

Here is an example in a Kendo Dojo

huangapple
  • 本文由 发表于 2023年7月31日 22:53:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76804799.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定