2022-01-17 21:53:43 +03:00
|
|
|
import {formatNumber} from './format-number';
|
2021-06-04 10:37:47 +03:00
|
|
|
import {helper} from '@ember/component/helper';
|
|
|
|
|
2022-05-10 18:35:51 +03:00
|
|
|
export function ghPriceAmount(amount, {cents = true} = {}) {
|
2021-06-04 10:37:47 +03:00
|
|
|
if (amount) {
|
2022-05-10 18:35:51 +03:00
|
|
|
let price = cents ? amount / 100 : Math.round(amount / 100);
|
2021-10-20 14:13:27 +03:00
|
|
|
if (price % 1 === 0) {
|
2022-01-17 21:53:43 +03:00
|
|
|
return formatNumber(price);
|
2021-10-20 14:13:27 +03:00
|
|
|
} else {
|
2022-01-18 12:45:55 +03:00
|
|
|
return formatNumber(Math.round(price * 100) / 100);
|
2021-10-20 14:13:27 +03:00
|
|
|
}
|
2021-06-04 10:37:47 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// like {{pluralize}} but formats the number according to current locale
|
2022-05-10 18:35:51 +03:00
|
|
|
export default helper(function ([amount], options = {}) {
|
|
|
|
return ghPriceAmount(amount, options);
|
2021-06-04 10:37:47 +03:00
|
|
|
});
|