Adding the values problem in C# and sql server

Posted by Gopal_nivas under ASP.NET on 1/20/2012 | Points: 10 | Views : 638 | Status : [Member] | Replies : 1
hi..

i get the values from my database like this:
"0.00581932067871094,0.0380859375,0.14695930480957,0.05712890625,0.4727173,0.00693511962890625,0.12841796875,0.4706268,0.025390625,0.983076095581055,1.20370292663574,0.51667308807373,0.05224609375,0.0105524063110352,0.32610034942627,0.205492973327637,0.12841796875,0.6494140625,1.102112,0.03515625,0.037109375,0.1011353,0.037109375,0.1011353,0.025390625,0.1255493,0.1265259,0.0402994155883789,0.3590698,0.470626831054688,0.068359375,0.06549072,0.0185546875,0.02252197,0.037109375,0.6494140625,1.102112,0.02685546875,0.02545166,0.025390625,0.1255493,0.037109375,0.1011353,0.0479126,0.05322265625,0.033203125,0.12841796875,0.05859375,0.025390625,0.1255493,0.1265259,0.6494140625,1.102112,0.025390625,0.1255493,0.983076095581055,0.12841796875".


if i programmatically adding these values i get the output as "13.9068066141968".

but when i add these values from SQL server using split function i get the output as "10.00".

i dont know what is happening and why the values are differed.
my sql code is:
DECLARE @STORAGESIZE NVARCHAR(MAX);
DECLARE @TOTALSTORAGESIZE NVARCHAR(MAX)
@STORAGESIZE = above mentioned values.

SELECT @TOTALSTORAGESIZE=SUM(CAST(PART AS NUMERIC(10,2))) FROM DBO.SPLITSTRING(@STORAGESIZE,',')

------------------------------

my C# code is:
---------------------------------
string _strInput = "0.00581932067871094,0.0380859375,0.14695930480957,0.05712890625,0.4727173,0.00693511962890625,0.12841796875,0.4706268,0.025390625,0.983076095581055,1.20370292663574,0.51667308807373,0.05224609375,0.0105524063110352,0.32610034942627,0.205492973327637,0.12841796875,0.6494140625,1.102112,0.03515625,0.037109375,0.1011353,0.037109375,0.1011353,0.025390625,0.1255493,0.1265259,0.0402994155883789,0.3590698,0.470626831054688,0.068359375,0.06549072,0.0185546875,0.02252197,0.037109375,0.6494140625,1.102112,0.02685546875,0.02545166,0.025390625,0.1255493,0.037109375,0.1011353,0.0479126,0.05322265625,0.033203125,0.12841796875,0.05859375,0.025390625,0.1255493,0.1265259,0.6494140625,1.102112,0.025390625,0.1255493,0.983076095581055,0.12841796875";



string[] _strarrInput = _strInput.Split(',');
double _iOutputSum = 0.0;
for (int i = 0; i < _strarrInput.Length; i++)
{
_iOutputSum = _iOutputSum + Convert.ToDouble(_strarrInput[i]);
}


string s = _iOutputSum.ToString();

------------------------------------------------

so how to tackle this..

need ur suggetsions..

which is the bets way to add the comma separated values?

regards
gopal.s




Responses

Posted by: Naraayanan on: 2/2/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Check this link.I hope this link will help you.
http://geekswithblogs.net/AngelEyes/archive/2007/04/12/111504.aspx


Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response