How do I change my double to only have 2 places before the decimal?

Like 12.50 instead of 12.501214234213. It’s a cash value so it has to have 2 decimal places in change.

Also How does the Formatter work.

Double.Parse(String, Formatter)

Hello @HsDev,

A quick solution could be using the toString function with a numberFormat or the Math.Round method.

For example:

double1=12.501214234213

double1.ToString(“##.00”) ------ output 12.50

System.Math.Round(double1,2).ToString — output 12.5

Best Regards,

Susana

Awesome. Could you possibly give me one more example of how String format works in a different context? Just so that I understand what’s going on here?

Hi @HsDev,

Custom Numeric Format strings might help you get more ideas.

Hope you find it useful.

Regards,

PD

Thank you! That helps tremendously. I’ll save it for future use as well.

Heather - if you are using the numbers for cash, you should use system.decimal datatype instead of system.double.

Double values are not precise at very small or very large numbers, so it’s always recommended to use decimal values instead for monetary amounts

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.