0

I want to remove the characters after 2 decimal values. while I'm formatting not getting any changes in the value. I don't want convert it to double and then string due to performance issue may arise.

data type is Float in the database
value -172.209
Exp op - 172.20

code

  string max_demand = dt_max_demand.Rows[0][0].ToString();
  max_demand= String.Format("{0:0.0#}", max_demand);

1 Answers1

0

You could search for the last '.' character in your string and then cut it after 2 more chars but it would be way more efficient and easier to format it using $"{dt_max_demand.Rows[0][0]:F2}", assuming dt_max_demand.Rows[0][0] has a numeric type before you cast it to a string.

  string max_demand = $"{dt_max_demand.Rows[0][0]:F2}";
0x54696d
  • 44
  • 5