【问题标题】:Shorten data numbers in tables缩短表格中的数据编号
【发布时间】:2018-01-05 00:38:17
【问题描述】:

我想缩短 json / datatable 上的数字。

我从一个网站上拿json数据,但是网站上的json显示的数字很详细。

例如:json 显示 408.43324032。我只想显示 408 或 408x。


我想这样展示。

有参考吗?我不知道叫什么名字来做这种东西。

任何帮助和参考将不胜感激。

【问题讨论】:

标签: javascript jquery json datatable


【解决方案1】:

console.log( 408.73324032.toFixed(0) )    // Fix and round to nearest
console.log( 408.73324032.toFixed(1) )    // Fix at 1 decimal and round to nearest
console.log( Math.round(408.73324032) )   // round to nearest
console.log( Math.floor(408.73324032) )   // round to lowest
console.log( Math.ceil(408.73324032) )    // round to upper
console.log( parseInt(408.73324032, 10) ) // integer only (radix 10)

toFixed(1) 非常适合您的目的

【讨论】:

  • 我会试试的。可以将数字更改为X吗?前任。 408x
  • Math.round(408.847345345) + 'x'; 会完成这项工作。
【解决方案2】:

这行得通吗?它似乎支持许多不同的格式和符号的后缀(我认为这是您所要求的)。

http://mottie.github.io/javascript-number-formatter/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 2015-08-15
    • 2021-12-21
    • 1970-01-01
    • 2013-03-29
    • 1970-01-01
    相关资源
    最近更新 更多