Home > Enterprise >  How to convert all floats to two decimal places regardless of number of decimal places float has wit
How to convert all floats to two decimal places regardless of number of decimal places float has wit

Time:12-15

Goal

I want to convert all floats to two decimal places regardless of number of decimal places float has without repeating convert code.

For example, I want to convert

50 to 50.00

50.5 to 50.50

without repeating the convert code again and again. What I mean is explained in the following section - research.

Not what this question is about

This question is NOT about

  1. Only limiting floats to two decimal points - if there is less than two decimal points then I want it to have two decimal points with zeros for the unused spaces

  2. Flooring the decimal or ceiling it

  3. Rounding the decimal off

This question is also not a duplicate of enter image description here

Decimal calculations are precise but it takes more time to do calculations, keep that in mind.

  • Related