Friday, May 17, 2024
171
rated 0 times [  172] [ 1]  / answers: 1 / hits: 28634  / 9 Years ago, wed, may 6, 2015, 12:00:00

tests: http://jsfiddle.net/su918rLv/



This is the how the existing formats work:



numeral(1234.567).format('0,0');
//output: 1,235

numeral(1234.567).format('0,0.00');
//output: 1,234.57

numeral(1234).format('0,0.00');
//output: 1,234.00


Is there a format that will produce both a whole number or decimal number based on the number value? I'm using 0,0.99 here but it is not the answer.



numeral(1234).format('0,0.99');
//output: 1,234

numeral(1234.567).format('0,0.99');
//output: 1,234.57

More From » string-formatting

 Answers
10

Yes. Put the optional decimals in brackets:



numeral(1234).format('0,0.[00]');
// output: 1,234

numeral(1234.567).format('0,0.[00]');
// output: 1,234.57

[#66710] Tuesday, May 5, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
isham

Total Points: 69
Total Questions: 86
Total Answers: 86

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
;