Feat/SW-1308 booking codes track b * feat: SW-1308 Booking codes track b * feat: SW-1308 Booking codes Track B implementation * feat: SW-1308 Optimized after rebase Approved-by: Arvid Norlin
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
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 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,
|
|
additionalPrice?: number,
|
|
additionalPriceCurrency?: string
|
|
) {
|
|
const localizedPrice = intl.formatNumber(price, {
|
|
minimumFractionDigits: 0,
|
|
})
|
|
return `${localizedPrice} ${currency} ${additionalPrice ? "+ " + additionalPrice + " " + additionalPriceCurrency : ""}`
|
|
}
|
|
|
|
// This will handle redemption and bonus cheque (corporate cheque) scneario with partial payments
|
|
export function formatPriceWithAdditionalPrice(
|
|
intl: IntlShape,
|
|
points: number,
|
|
pointsCurrency: string,
|
|
additionalPrice?: number,
|
|
additionalPriceCurrency?: string
|
|
) {
|
|
const formattedAdditionalPrice =
|
|
additionalPrice && additionalPriceCurrency
|
|
? `+ ${formatPrice(intl, additionalPrice, additionalPriceCurrency)}`
|
|
: ""
|
|
|
|
return `${formatPrice(intl, points, pointsCurrency)} ${formattedAdditionalPrice}`
|
|
}
|