Merged in feat/sw-3225-move-parking-information-to-booking-flow (pull request #2614)
feat(SW-3225): Move ParkingInformation to design-system * Inline ParkingInformation types to remove trpc dependency * Move ParkingInformation to design-system * Move numberFormatting to common package * Add deps to external * Fix imports and i18n script * Add common as dependency * Merge branch 'master' into feat/sw-3225-move-parking-information-to-booking-flow Approved-by: Linus Flood
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
"./utils/isDefined": "./utils/isDefined.ts",
|
||||
"./utils/maskValue": "./utils/maskValue.ts",
|
||||
"./utils/dateFormatting": "./utils/dateFormatting.ts",
|
||||
"./utils/numberFormatting": "./utils/numberFormatting.ts",
|
||||
"./utils/rangeArray": "./utils/rangeArray.ts",
|
||||
"./utils/zod/*": "./utils/zod/*.ts",
|
||||
"./utils/debounce": "./utils/debounce.ts",
|
||||
|
||||
41
packages/common/utils/numberFormatting.ts
Normal file
41
packages/common/utils/numberFormatting.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
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}`
|
||||
}
|
||||
Reference in New Issue
Block a user