Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions src/locales/en_US.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
};

/**
Expand All @@ -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){
Expand All @@ -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("");
};

Expand Down
2 changes: 1 addition & 1 deletion src/numbers2words.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down