0

I have a C# application with the following code:

foreach(var record in localFundData)
        {
            sendData.TotalPlanAssets += Math.Round(double.Parse(record.FPCR_Fund_Value),2);

            if (record.FPCR_Ref_Fund == localLoanFund)
            {
                sendData.TotalLoanBalance = Math.Round(double.Parse(record.FPCR_Fund_Value),2);
            }

        }

The field sendData.TotalPlanAssets is defined as double and the field record.FPCR_Fund_Value is defined as a string.

I have a breakpoint set at the IF command so I can see what the values of record.FPCR_Fund_Value and sendData.TotalPlanAssets are as I progress through the loop.

This is what I get as I run through the loop:

Pass # 1 record.FPCR_Fund_Value = "0.00 " sendData.TotalPlanAssets = 0.00

Pass # 2 record.FPCR_FundValue = "16,377.23 " sendData.TotalPlanAssets = 16377.23

Pass # 3 record.FPCR_FundValue = "2,458.68 " sendData.TotalPlanAssets = 18835.91

Pass # 4 record.FPCR_FundValue = "18,240.23 " sendData.TotalPlanAssets = 37076.14

Pass # 5 record.FPCR_FundValue = "159,887.90 " sendData.TotalPlanAssets = 196964.03999999998

Why does this happen? Obviously, I am just trying to accumulate the values that come back in the record.FPCR_FundValue fields to give me a total dollar amount.

Any assistance is greatly appreciated.

Jonathan Small
  • 1,027
  • 3
  • 18
  • 40

0 Answers0