fix: align price formatting
This commit is contained in:
@@ -1,8 +1,32 @@
|
||||
import type { IntlShape } from "react-intl"
|
||||
|
||||
/**
|
||||
* Function to parse number with single decimal if any
|
||||
* @param n
|
||||
* @returns number in float type with single digit decimal if any
|
||||
*/
|
||||
export default function getSingleDecimal(n: Number | string) {
|
||||
export function getSingleDecimal(n: Number | string) {
|
||||
return parseFloat(Number(n).toFixed(1))
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to parse number for i18n format for prices with currency
|
||||
* @param intl - react-intl object
|
||||
* @param price - number to be formatted
|
||||
* @param currency - currency code
|
||||
* @returns localized and formatted number in string type with currency
|
||||
*/
|
||||
export function formatPrice(
|
||||
intl: IntlShape,
|
||||
price: number,
|
||||
currency?: string | null
|
||||
) {
|
||||
if (!currency) {
|
||||
return intl.formatNumber(price)
|
||||
}
|
||||
return intl.formatNumber(price, {
|
||||
style: "currency",
|
||||
currency,
|
||||
minimumFractionDigits: 0,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user