File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed
Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -80,19 +80,23 @@ module.exports = {
8080 return hours + ':' + remainingMinutes ;
8181 } ,
8282
83- number ( value , precision ) {
83+ number ( value , precision = 2 ) {
8484 if ( typeof value !== 'number' ) {
8585 throw new TypeError ( 'Expected value to be a of type Number' ) ;
8686 } else if ( isNaN ( value ) ) {
8787 throw new Error ( 'Expected value to be a valid Number not NaN' ) ;
8888 } else if ( ! isFinite ( value ) ) {
8989 throw new Error ( 'Expecte value not to be a finite value.' ) ;
9090 }
91- precision = precision || 2 ;
92- return String ( value . toFixed ( precision ) ) ;
91+ const options = {
92+ minimumFractionDigits : precision ,
93+ maximumFractionDigits : precision ,
94+ } ;
95+ const locale = 'en-EN' ;
96+ return value . toLocaleString ( locale , options ) ;
9397 } ,
9498
95- price ( value , precision ) {
99+ price ( value , precision = 2 ) {
96100 precision = precision || 2 ;
97101 return String ( value . toFixed ( precision ) ) ;
98102 } ,
Original file line number Diff line number Diff line change @@ -58,6 +58,9 @@ describe('formater', () => {
5858 it ( 'can have a differenct precision' , ( ) => {
5959 expect ( formater . number ( 2.128391 , 4 ) ) . to . equal ( '2.1284' ) ;
6060 } ) ;
61+ it ( 'adds thousand seperator' , ( ) => {
62+ expect ( formater . number ( 29828172.21 ) ) . to . equal ( '29,828,172.21' ) ;
63+ } ) ;
6164 it ( 'throws an exception when the first argument is not a number' , ( ) => {
6265 expect ( ( ) => formater . number ( null ) ) . to . throw ( TypeError ) ;
6366 expect ( ( ) => formater . number ( 8 / 0 ) ) . to . throw ( Error ) ;
You can’t perform that action at this time.
0 commit comments