Skip to content
Permalink
Browse files

fix: remove spaces from decimal part of currency value

  • Loading branch information...
mkczarkowski committed May 19, 2018
1 parent 1b68d32 commit a544a5140d18a635614b7fbe12e225efe1a47ed6
Showing with 12 additions and 3 deletions.
  1. +12 −3 src/shared/utils/helpers.js
@@ -1,6 +1,15 @@
export default function formatAsCurrency(value) {
const currencyFormatRegex = /\B(?=(\d{3})+(?!\d))/g;
return `$${String(value)
.replace(currencyFormatRegex, ' ')
.trim()}`;
const separator = '.';
const [wholePart, decimalPart] = String(value).split(separator);
const wholePartFormattedAsCurrency = wholePart.replace(
currencyFormatRegex,
' ',
);
const formattedValue = decimalPart
? [wholePartFormattedAsCurrency, decimalPart].join(separator)
: wholePartFormattedAsCurrency;

return `$${formattedValue}
`;
}

0 comments on commit a544a51

Please sign in to comment.
You can’t perform that action at this time.