var string = numeral(2.567).format('0,0.00');
// '2.57'
I don't want a rounding,I need to throw away the last digit,so the result should be 2.56.
so,how should I config it?
I don't think you're going to be able to do that with just numeral. You could use some sort of helper function to round your number first (adapted from MDN example): https://jsfiddle.net/0cxwbdhw/1/
var myNamespace = {};
myNamespace.floor = function(number, precision) {
var factor = Math.pow(10, precision);
var tempNumber = number * factor;
var roundedTempNumber = Math.floor(tempNumber);
return roundedTempNumber / factor;
};
myNamespace.floor(2.567, 2); // 2.56
I'd be curious to know why you want to do this, though, since it's counter-intuitive to how rounding normally works.
could you add an option to config the rounding behavior?
check this for help: https://github.com/adamwdraper/Numeral-js/issues/505
Thanks, we're using it for displaying currency numbers, and we need to summarize numbers without having them rounded up.
try:
var string = numeral(2.567 - 0.005).format('0,0.00'); // '2.56'
var string = numeral(2.562 - 0.005).format('0,0.00'); // '2.56'
Most helpful comment
could you add an option to config the rounding behavior?