Reputation: 39258
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.
Upvotes: 5
Views: 1961
Reputation: 21
kendo.toString(kendo.format('{0:P1}', percentage)).replace(' ','')
Upvotes: 2
Reputation: 31
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.
Upvotes: 3
Reputation: 20203
You can use something like this.
kendo.format("{0:######.#####%}", 22.33)
More info about the format method can be found here.
Upvotes: 3
Reputation: 84
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 ''
Upvotes: 1