Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align number values by decimal material ui table react

In my React application I'm using Material UI table to display the list of products. I would like to align the price by decimal point. table

like image 383
praveen guda Avatar asked Oct 15 '25 16:10

praveen guda


1 Answers

Create a function like this code and you can pass number in numberFormat. You can change maxSpace value and paddingRight multiply value whatever you need. Check this working example code here

const numberFormat = num => {
  let len = 0;
  if (num.toString().split(".")[1] >= 0) {
    len = num.toString().split(".")[1].length;
  }
  const maxSpace = 4;
  return <div style={{ paddingRight: (maxSpace - len) * 8 }}>{num}</div>;
};

Check this image, you can change paddingRight for every row as your need

enter image description here

like image 150
Arpit Avatar answered Oct 18 '25 06:10

Arpit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!