mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 05:50:35 +03:00
20 lines
634 B
JavaScript
20 lines
634 B
JavaScript
import {formatNumber} from './format-number';
|
|
import {helper} from '@ember/component/helper';
|
|
|
|
export function ghPriceAmount(amount, {cents = true} = {}) {
|
|
if (amount) {
|
|
let price = cents ? amount / 100 : Math.round(amount / 100);
|
|
if (price % 1 === 0) {
|
|
return formatNumber(price);
|
|
} else {
|
|
return formatNumber(Math.round(price * 100) / 100, {minimumFractionDigits: 2});
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// like {{pluralize}} but formats the number according to current locale
|
|
export default helper(function ([amount], options = {}) {
|
|
return ghPriceAmount(amount, options);
|
|
});
|