.Split cuts off a number

  • Thread starter Thread starter mike
  • Start date Start date
M

mike

In my array i have 10|5.98

string[] mySplit = myArray.Split('|');
string DeliveryAddress = mySplit[0];
string ShippingID = mySplit[1];

my problem is ShippingID contains 5.9 not 5.98

can anyone tell me where my last number has gone, or how i get around this
problem?

Thanks in advance
Mike
 
mike said:
In my array i have 10|5.98

string[] mySplit = myArray.Split('|');
string DeliveryAddress = mySplit[0];
string ShippingID = mySplit[1];

my problem is ShippingID contains 5.9 not 5.98

can anyone tell me where my last number has gone, or how i get around this
problem?

I suspect your problem doesn't lie where you think it does.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

Here's a short but complete example which *doesn't* show the problem -
it shows Split working perfectly well:

using System;

class Test
{
static void Main()
{
string myArray = "10|5.98";
string[] mySplit = myArray.Split('|');
string DeliveryAddress = mySplit[0];
string ShippingID = mySplit[1];
Console.WriteLine(DeliveryAddress);
Console.WriteLine(ShippingID);
}
}
 
Hi Mike,

Split has always worked fine with me, are you sure that myArray ( a string
variable right? ) contain the value you think?
I will try to guess here, but it seems that you build this value somewhere
from two numeric values, maybe the numeric value is 5.98 but it gets rounded
to 5.9 somehow?

Cheers,
 
Back
Top