admin管理员组文章数量:1315792
In Kendo I use kendo.toString(value, "p0")
to format a string to include a percentage symbol.
kendo.toString(12, "p0")
renders as 12 %. Is there a way to avoid the space between the number and the percent sign? I would like to render it as 12% instead.
I can of course take care of it manually, but I was wondering if there is a built in way to prevent manual formatting here.
In Kendo I use kendo.toString(value, "p0")
to format a string to include a percentage symbol.
kendo.toString(12, "p0")
renders as 12 %. Is there a way to avoid the space between the number and the percent sign? I would like to render it as 12% instead.
I can of course take care of it manually, but I was wondering if there is a built in way to prevent manual formatting here.
4 Answers
Reset to default 3You can use something like this.
kendo.format("{0:######.#####%}", 22.33)
More info about the format method can be found here.
The Kendo formats are stored as definitions in the "cultures" object. The default culture is "en-US" (US English), and you can replace the percentage format used throughout by doing this at document ready time:
kendo.cultures["en-US"].numberFormat.percent.pattern = ["-n%", "n%"];
I was puzzled about that odd space too, it looks particularly disconcerting in chart axis labels.
kendo.toString(kendo.format('{0:P1}', percentage)).replace(' ','')
You can use built in javascript regular expression.
var yourstring = "12 %";
yourstring.replace(/\s+/g,''); // replaces all spaces using regex
\s+ means spaces, including multiple spaces in a row
g means as many times as possible in the string
'' is what character you want to replace the space with. In this case it's nothing ''
本文标签: javascriptRemove space between percentage symbol and number in KendoStack Overflow
版权声明:本文标题:javascript - Remove space between percentage symbol and number in Kendo - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741991221a2409145.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论