diff --git a/src/components/FamilyAcc/Tabs/wallet/FamilyAddFundPopout.jsx b/src/components/FamilyAcc/Tabs/wallet/FamilyAddFundPopout.jsx index 8e1b940..0dce186 100644 --- a/src/components/FamilyAcc/Tabs/wallet/FamilyAddFundPopout.jsx +++ b/src/components/FamilyAcc/Tabs/wallet/FamilyAddFundPopout.jsx @@ -4,6 +4,7 @@ import InputCom from '../../../Helpers/Inputs/InputCom' import { Form, Formik } from "formik"; import * as Yup from "yup"; +import {AmountTo2DP} from '../../../Helpers/PriceFormatter' import usersService from '../../../../services/UsersService'; import LoadingSpinner from '../../../Spinners/LoadingSpinner'; import { PriceFormatter } from '../../../Helpers/PriceFormatter'; @@ -42,7 +43,7 @@ function FamilyAddFundPopout({action, situation, wallet, familyData}) { // initial values for formik let initialValues = { amount: '', - from : startTransfer?.data?.origing_current_balance*0.01 || 'N/A', + from : AmountTo2DP(startTransfer?.data?.origing_current_balance*0.01), to: `${familyData.firstname} ${familyData.lastname}`, comment: '' }; diff --git a/src/components/Helpers/PriceFormatter.jsx b/src/components/Helpers/PriceFormatter.jsx index 49b5bb5..540a399 100644 --- a/src/components/Helpers/PriceFormatter.jsx +++ b/src/components/Helpers/PriceFormatter.jsx @@ -50,3 +50,29 @@ export const PriceFormatter = ( ); }; + + +// FUNCTION TO RETURN AMOUNT TO TWO DECIMAL PLACES +export const AmountTo2DP = ( + amount = "00", +) => { + // Convert the number to a string + let numStr = String(amount); + + // Split the string into integer and decimal parts + let parts = numStr.split("."); + let integerPart = parts[0] || ""; + let decimalPart = parts[1] || ""; + + // Add thousands separators to the integer part + let formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ','); + + // Truncate or pad the decimal part to two decimal points + let formattedDecimal = decimalPart.slice(0, 2).padEnd(2, "0"); + + // Combine the formatted integer and decimal parts + let formattedNumber = formattedInteger + '.' + formattedDecimal; + + // return formattedNumber; + return formattedNumber; +}; \ No newline at end of file