Heram Sharma Heram Sharma - 1 year ago 94
C# Question

auto round value by decimal datatype in C# programming

I have problem with one variable that i have declared with decimal datatype and it need to be with decimal datatype i don't wanna change that datatype because i need it on another part as well.

What exactly i need

I am getting 2.12 as discount value. that i have assign to one variable dynamically.

//I am getting 2.12 here
decimal discount = Convert.ToDecimal(label.text); //it convert to 3 (round figure)

Answer Source

Try specifying a culture.

decimal discount = Convert.ToDecimal(label.text, CultureInfo.InvariantCulture);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download