Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to prevent auto deleting 0 after .?

I want to display $125.00, but insted I get $125, how to prevent it

import { Typography } from "@mui/material";

function ProductPrize({}) {
  const presentPrize = 125.0;
  return (
    <Typography variant="h4" sx={{ fontWeight: "bold" }}>
      {`$${presentPrize}`}
    </Typography>
  );
}

export default ProductPrize;

I tried parsefloat etc.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

JavaScript prints out the minimum number of decimal points it needs to. If you always want 2 decimal points, you can change the code to the following:

<Typography variant="h4" sx={{ fontWeight: "bold" }}>
  {`$${(Math.round(presentPrize * 100) / 100).toFixed(2)}`}
</Typography>

This with round 1.236 to $1.24

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading