react-countup
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -29,3 +29,4 @@ 'use strict'; | ||
var formatNumber = exports.formatNumber = function formatNumber(start, options) { | ||
var num = '' + start.toFixed(options.decimals); | ||
var neg = start < 0; | ||
var num = '' + Math.abs(start).toFixed(options.decimals); | ||
var x = num.split('.'); | ||
@@ -41,3 +42,4 @@ var x1 = x[0]; | ||
} | ||
return '' + options.prefix + x1 + x2 + options.suffix; | ||
return '' + (neg ? '-' : '') + (options.prefix || '') + x1 + x2 + (options.suffix || ''); | ||
}; | ||
@@ -44,0 +46,0 @@ |
{ | ||
"name": "react-countup", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "A React component wrapper around CountUp.js", | ||
@@ -5,0 +5,0 @@ "author": "Glenn Reyes <glenn@glennreyes.com> (https://twitter.com/glnnrys)", |
@@ -100,5 +100,2 @@ # [React CountUp](https://glennreyes.github.io/react-countup) | ||
##### `useGrouping`: boolean | ||
Group thousands by [separator character](#separator-string) | ||
##### `separator`: string | ||
@@ -105,0 +102,0 @@ Specifies character of thousands separator |
@@ -75,1 +75,10 @@ import React from 'react'; | ||
}); | ||
it('formats negative number with separator correctly', () => { | ||
const formattedNumber = formatNumber(-123456.789, { | ||
decimal: '.', | ||
decimals: 2, | ||
separator: ' ', | ||
}); | ||
expect(formattedNumber).toBe('-123 456.79'); | ||
}); |
@@ -40,3 +40,4 @@ // @flow | ||
export const formatNumber: FormatNumberFn = (start, options) => { | ||
const num = `${start.toFixed(options.decimals)}`; | ||
const neg = start < 0; | ||
const num = `${Math.abs(start).toFixed(options.decimals)}`; | ||
const x = num.split('.'); | ||
@@ -52,3 +53,5 @@ let x1 = x[0]; | ||
} | ||
return `${options.prefix}${x1}${x2}${options.suffix}`; | ||
return `${neg ? '-' : ''}${options.prefix || ''}${x1}${x2}${options.suffix || | ||
''}`; | ||
}; | ||
@@ -55,0 +58,0 @@ |
18994
367
162