Skip to content
Open
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
14 changes: 14 additions & 0 deletions src/number_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,18 @@ class NumberFormat extends React.Component {
}
/** caret specific methods ends **/

convertFullwidthToHalfwidth = (val: string) => {
let ascii = '';
for(let i=0, l=val.length; i<l; i++) {
let c = val[i].charCodeAt(0);
// make sure we only convert half-full width char
if (c >= 0xFF00 && c <= 0xFFEF) {
c = 0xFF & (c + 0x20);
}
ascii += String.fromCharCode(c);
}
return ascii
}

/** methods to remove formattting **/
removePrefixAndSuffix(val: string) {
Expand Down Expand Up @@ -603,6 +615,8 @@ class NumberFormat extends React.Component {
const {selectionStart, selectionEnd} = this.selectionBeforeInput;
const {start, end} = findChangedIndex(lastValue, value);

value = this.convertFullwidthToHalfwidth(value)

/** Check if only . is added in the numeric format and replace it with decimal separator */
if (!format && decimalSeparator !== '.' && start === end && value[selectionStart] === '.') {
return value.substr(0, selectionStart) + decimalSeparator + value.substr(selectionStart + 1, value.length);
Expand Down