Skip to content

Commit 36de2ba

Browse files
committed
Negative signs should come before the prefix.
1 parent de157e4 commit 36de2ba

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ Optionally set a currency symbol as a prefix or suffix
9696
```
9797
9898
99+
Negative signs come before the prefix
100+
```javascript
101+
// -$20.00
102+
<CurrencyInput prefix="$" value="-20.00" />
103+
```
104+
105+
106+
99107
100108
All other attributes are applied to the input element. For example, you can integrate bootstrap styling:
101109

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-currency-input",
3-
"version": "1.0.9",
3+
"version": "1.0.10",
44
"description": "React component for inputing currency amounts",
55
"main": "lib/index.js",
66
"scripts": {

src/mask.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,15 @@ export default function mask(value, precision, decimalSeparator, thousandSeparat
6363
digits.splice(x, 0, thousandSeparator);
6464
}
6565

66+
// if we have a prefix or suffix, add them in.
67+
if (prefix.length > 0){digits.unshift(prefix);}
68+
if (suffix.length > 0){digits.push(suffix);}
69+
6670
// if the number is negative, insert a "-" to
6771
// the front of the array
6872
if (allowNegative && numberIsNegative) {
6973
digits.unshift('-');
7074
}
7175

72-
// if we have a prefix or suffix, add them in.
73-
if (prefix.length > 0){digits.unshift(prefix);}
74-
if (suffix.length > 0){digits.push(suffix);}
75-
76-
7776
return digits.join('').trim();
7877
}

test/mask.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ describe('mask', function(){
143143
expect(mask("0","2",".",",",true,""," kr ")).to.equal("0.00 kr");
144144
});
145145

146+
147+
it('"-" should come before the prefix', function(){
148+
expect(mask("-20.00","2",".",",",true,"$","")).to.equal("-$20.00");
149+
});
150+
146151
});
147152

148153

0 commit comments

Comments
 (0)