Skip to content

Commit

Permalink
Fixed issue with dot separator when decimalScale is set to zero #375
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei97k authored and s-yadav committed Feb 20, 2020
1 parent 97ccf23 commit c327ebe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/number_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,8 @@ class NumberFormat extends React.Component {

/** Check for any allowed decimal separator is added in the numeric format and replace it with decimal separator */
if (!format && start === end && allowedDecimalSeparators.indexOf(value[selectionStart]) !== -1 ) {
return value.substr(0, selectionStart) + decimalSeparator + value.substr(selectionStart + 1, value.length);
const separator = this.props.decimalScale === 0 ? '' : decimalSeparator;
return value.substr(0, selectionStart) + separator + value.substr(selectionStart + 1, value.length);
}

/* don't do anyhting if something got added,
Expand Down
11 changes: 11 additions & 0 deletions test/library/input_numeric_format.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,17 @@ describe('Test NumberFormat as input with numeric format options', () => {
expect(wrapper.state().value).toEqual('$000012,345,678');
});

//Issue #375
it('should give correct formatted value when pasting the dot symbol with decimal scale is set to zero, issue #375', () => {
const wrapper = shallow(<NumberFormat
value={4200}
thousandSeparator={true}
decimalScale={0}
/>);
simulateKeyInput(wrapper.find('input'), '.', 2, 2);
expect(wrapper.state().value).toEqual('4,200');
});

describe('Test thousand group style', () => {
it('should format on english style thousand grouping', () => {
const wrapper = shallow(<NumberFormat thousandSeparator={true} value={12345678}/>);
Expand Down

0 comments on commit c327ebe

Please sign in to comment.