Files
web/apps/scandic-web/utils/numberFormatting.ts
Hrishikesh Vaipurkar 73cb423c95 Merged in feat/SW-2078-update-confirmation-page-vouchers (pull request #1731)
Feat/SW-2078 update confirmation page vouchers and Corp Cheques rate

* feat: SW-2078 Tablet bookingCode ref forward issue fix

(cherry picked from commit 16a6a00fd99b6b6220a98ad74de062d67d35e1c0)

* feat: SW-2078 Display Vouchers and Cheques prices on confirmation page

(cherry picked from commit a76494de497a7d5e7641cb0036bd7055acf875c1)

* feat: SW-2078 Rebase issue fix

* feat: SW-2079 Updated rate title in terms modal

* feat: SW-2078 Optimized code

* feat: SW-2078 Removed extra tags


Approved-by: Christian Andolf
2025-04-08 07:27:40 +00:00

42 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
* @param additionalPrice - number (obtained in reward nights and Corporate cheque scenarios)
* @param additionalPriceCurrency - currency code (obtained in reward nights and Corporate cheque scenarios)
* @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,
})
let formattedAdditionalPrice: string = ""
if (additionalPrice && additionalPriceCurrency) {
const localizedAdditionalPrice = intl.formatNumber(additionalPrice, {
minimumFractionDigits: 0,
})
formattedAdditionalPrice = ` + ${localizedAdditionalPrice} ${additionalPriceCurrency}`
}
return `${localizedPrice} ${currency}${formattedAdditionalPrice}`
}