Skip to content

Instantly share code, notes, and snippets.

@mkamakura
Last active January 15, 2018 01:57
Show Gist options
  • Save mkamakura/85276a2d3035bbb256c67652096cba81 to your computer and use it in GitHub Desktop.
Save mkamakura/85276a2d3035bbb256c67652096cba81 to your computer and use it in GitHub Desktop.
// @flow
export function formatPriceYen(price: number): string {
return `¥${formatPrice(price)}`
}
export function formatPriceYenMonth(price: number): string {
return `${formatPriceYen(price)}/月`
}
export function formatPrice(price: number): string {
return String(price).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,')
}
export function formatRange(range: { min?: number, max?: number }): string {
const { min, max } = range
if (!min && !max) return ''
return `${min ? formatPriceYenMonth(min) : ''}〜${max ? formatPriceYenMonth(max) : ''}`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment