0

Need a way to deal with number format in react admin. I tried to change the format with Record Context. But my calculation went wrong. I need something like this

5000000000 --> 5,000,000,000

Thank you

Edward Tan
  • 13
  • 1
  • Does this answer your question? [Regular Expression for formatting numbers in JavaScript](https://stackoverflow.com/questions/2254185/regular-expression-for-formatting-numbers-in-javascript) – Tim Biegeleisen Oct 01 '21 at 09:11

2 Answers2

0

You can use the functions - parse / format. "Transforming Input Value to/from Record": https://marmelab.com/react-admin/Inputs.html#recipes

MaxAlex
  • 2,919
  • 1
  • 14
  • 14
0

I have been using this function to format numbers:

export const formatDecimals = (figure) => {
  return figure && figure.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};
Miguel Araya
  • 404
  • 3
  • 10