Files
web/apps/scandic-web/utils/numberFormatting.ts
Hrishikesh Vaipurkar c5e294c7ea Merged in feat/SW-1356-reward-night-booking-2- (pull request #1559)
feat: SW-1356 Reward night bookingflow

* feat: SW-1356 Reward night bookingflow

* feat: SW-1356 Removed extra param booking call

* feat: SW-1356 Optimized as review comments

* feat: SW-1356 Schema validation updates

* feat: SW-1356 Fix after rebase

* feat: SW-1356 Optimised price.redemptions check

* feat: SW-1356 Updated Props naming


Approved-by: Arvid Norlin
2025-03-24 08:54:02 +00:00

41 lines
1.3 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) {
const localizedPrice = intl.formatNumber(price, {
minimumFractionDigits: 0,
})
return `${localizedPrice} ${currency}`
}
// 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}`
}