How can I get the number of decimal places of a decimal
variable?
Eg: If I receive the number:
4.5 - should return 1
5.65 - should return 2
6.997 - should return 3
I know you can do this by converting to string
, something like:
decimal CasasDecimais(decimal arg){
return arg.ToString().Substring(arg.ToString().LastIndexOf(",") + 1).Length;
}
And I've also seen this question of SOen, but I would welcome alternatives to these two forms.