Skip to main content

formatToCurrency

13.560.000

import { formatToCurrency } from 'app-functions';
export const formatToCurrency = (number, decimal = ',') => {
if (!number) return;
let str = number.toString().split('').reverse().join('');
var n = str.match(/.{1,3}/g);
for (var i = 0; i < n.length; i++) n[i] = n[i].split('').reverse().join('');
str = n.reverse().join(decimal);
return str;
};
export const App = () => {
const [value, setValue] = React.useState('13560000');
return (
<div className="box-border">
<Input
onChange={(e) => setValue(e.target.value)}
value={value}
className="w-50"
placeholder="یک متن با اعداد انگلیسی وارد کنید"
/>
<Typography className="mt-24">{formatToCurrency(value, '.')}</Typography>
</div>
);
};