最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Remove space between percentage symbol and number in Kendo - Stack Overflow

programmeradmin1浏览0评论

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.

Share Improve this question asked Mar 19, 2014 at 19:04 TGHTGH 39.3k12 gold badges105 silver badges140 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

You 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 ''

发布评论

评论列表(0)

  1. 暂无评论