Created
April 18, 2017 16:31
-
-
Save andrIvash/b555c9ab6ac73c532f989a386fd0d557 to your computer and use it in GitHub Desktop.
Правильный вывод цены по разрядам
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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