Jayanta Mukherjee

Jayanta Mukherjee

  • NA
  • 120
  • 43.2k

How to convert one decimal place numbers to two decimal place c#

Nov 13 2021 1:27 PM

Hi, 

I have a weird situation here. I've got some data in excel format like below (sample):

ITEM QUANTITY RATE/UNIT
ABC 2 97.8
ASD 13 125.2
ZXC 1 294
QWE 5 35.7
POI 7 201
LKJ 30 177.1
MNB 25 208.1
XYZ 18 123.3

Also, I've been given the sumtotal value i.e. the total after (QUANTITY x RATE/UNIT) of each item which in this case is 16431.02. But if I do a sumproduct  on excel on the given data it gives 16437.60 which is due to the data of column RATE/UNIT being rounded to either 0 or 1 place after decimal place (.) and pasted as value so I cannot know what the two decimal value of the cell should be.

I'm trying to convert the data of column RATE/UNIT to numbers with two decimal places using the available data mentioned above using c#.

Can anybody help me on this ?


Answers (10)