巧用kendo.format和kendo.toString 格式化0为空格(不显示)

一般格式:
kendo.format("{0:0.00}", 5)      // 5.00
kendo.format("{0:0.00}", -5)      // -5.00
kendo.format("{0:0.##}", -5)                    // -5 
kendo.format("{0:0.##}", -5.00) // -5 

带千位符(,)
kendo.format("{0:#,0.00}", 5000.00)       //  5,000.00
kendo.format("{0:#,0.##}", 5000.00)       //  5,000
kendo.format("{0:#,0.##}", 5000.123)     //  5,000.12
kendo.format("{0:#,#.##}", 5000.123)     //  5,000.12

0(零)不显示。
注意:用分号(;)分成3段,如: {0:正数格式;负数格式;零格式}
kendo.format("{0:#,#.00;-#,#.00; }", 5000.123)   // 5,000.12 
kendo.format("{0:#,#.00;-#,#.00; }", -5000.123   // -5,000.12 
kendo.format("{0:#,#.00;-#,#.00; }", 0)    // 空格 (注意:第3段空格”不要漏了)

如果想了解更多,可以看Kendo API 
http://docs.telerik.com/kendo-ui/api/javascript/kendo#methods-format
http://docs.telerik.com/kendo-ui/framework/globalization/numberformatting 底部有这一行
"The ";" is the section separator. It defines sections with separate format strings for positive, negative, and zero numbers."

说明用kendo.toString也可以实现类似效果:
kendo.toString(5000.123, "#,#.##;-#,#.00; ")      // 5,000.12
kendo.toString(-5000.123, "#,#.##;-#,#.00; ")     // -5,000.12
kendo.toString(0, "#,#.##;-#,#.00; ")                   // 空格 (注意:第3段的“空格”不要漏了)

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值