mercredi 24 juin 2020

Return number of decimal places a float has

Is there a way to return the amount of decimal places a float currently has?

For example:

getPrecision(42.123f); // returns 3
getPrecision(42.123456f); // returns 6
getPrecision(42.01f); // returns 2
getPrecision(42.0f); // returns 0

Aucun commentaire:

Enregistrer un commentaire