Skip to content

Instantly share code, notes, and snippets.

@andrIvash
Created April 18, 2017 16:31
Show Gist options
  • Select an option

  • Save andrIvash/b555c9ab6ac73c532f989a386fd0d557 to your computer and use it in GitHub Desktop.

Select an option

Save andrIvash/b555c9ab6ac73c532f989a386fd0d557 to your computer and use it in GitHub Desktop.
Правильный вывод цены по разрядам
export default function priceFormat(price) {
const arr = [];
String(price).split('').reverse().forEach((c, i) => {
if (i % 3 === 0 ) {
arr.push(' ')
}
arr.push(c)
});
return arr.reverse().join('').trim()
}
// priceFormat(price) => 23 000 000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment