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 a544a51 commit c0a8e0dfa8c4c2b5e07e6765b507b615df62e298
Showing with 7 additions and 5 deletions.
  1. +7 −5 src/shared/utils/helpers.js
@@ -2,14 +2,16 @@ export default function formatAsCurrency(value) {
const currencyFormatRegex = /\B(?=(\d{3})+(?!\d))/g;
const separator = '.';
const [wholePart, decimalPart] = String(value).split(separator);

const wholePartFormattedAsCurrency = wholePart.replace(
currencyFormatRegex,
' ',
);
const formattedValue = decimalPart
? [wholePartFormattedAsCurrency, decimalPart].join(separator)
: wholePartFormattedAsCurrency;

return `$${formattedValue}
`;
const formattedValue =
typeof decimalPart !== 'undefined'
? [wholePartFormattedAsCurrency, decimalPart].join(separator)
: wholePartFormattedAsCurrency;

return `$${formattedValue}`;
}

0 comments on commit c0a8e0d

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