diff --git a/README.md b/README.md index 5ac6988..315ab21 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ translator.toWords(1234) ##Now available locales - id_ID (0...999999999) - de_DE (0...999999999) - - en_US (0...999999999) + - en_US (-999999999...999999999) - cs_CZ (0...999999999) **You can implement your locale vocabulary**. For additional locale send pull request with locale file + tests. diff --git a/src/locales/en_US.js b/src/locales/en_US.js index 692cc8d..6c81420 100644 --- a/src/locales/en_US.js +++ b/src/locales/en_US.js @@ -16,7 +16,8 @@ T2W.EN_US.DICTIONARY = { tens :[ "", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" ], hundred :"hundred", radix :["", "thousand", "million"], - delimiters :["-", "and"] + delimiters :["-", "and"], + signs :["minus"] }; /** @@ -40,7 +41,7 @@ T2W.EN_US.MAX_NUMBERS = 9; * @param {number} index * @return {string} */ -T2W.EN_US.prototype.translate = function( numbers ) { +T2W.EN_US.prototype.translate = function( numbers, sign ) { // Check max value if(numbers.length * T2W.EN_US.TOKEN_LENGTH > T2W.EN_US.MAX_NUMBERS){ @@ -60,6 +61,8 @@ T2W.EN_US.prototype.translate = function( numbers ) { words.unshift( this._getTrio( this.tokenize( numbers[idx], 1 ), idx, max)); } + if(sign === false) words.unshift( T2W.EN_US.DICTIONARY.signs[0] + " " ); + return words.join(""); }; diff --git a/src/numbers2words.js b/src/numbers2words.js index ed45cb7..1dbae08 100644 --- a/src/numbers2words.js +++ b/src/numbers2words.js @@ -86,7 +86,7 @@ T2W.prototype.toWords = function( number ){ }; } - return this.translate( this.tokenize(number, this._tokenLength)); + return this.translate( this.tokenize(number, this._tokenLength), Math.sign(number) > 0); }; /**