Parsing some XML-files to use in databses.
One of the data is a persons height.
In files it is given in feet - like 5.58.
Convert.ToDouble(), double.Parse() and double.TryParse() all return 558 - which is not correct.
I have tried with both single and double as the type - and the result is the same. Conversion pretents there is no decimal point.
Anybody has any idea, why this simple task is not possible in Visual Studio 2015?
Loading
Rafnas T PPosted Mar 20, 2017, 8:41 AM
Birger SørensenPosted Mar 20, 2017, 1:37 PM
Same problem (also can still not find tables in database, other than inside the IDE).
Inserted a test:
Person.Height = Double.Parse("5.58");
It still returns the number 558
If I write
Person.Height = 5.58;
everything is just fine; Person.Height IS = 5.58
Birger SørensenPosted Mar 20, 2017, 9:24 AM
I also could split the string at the . and calculate the value myself, as it seems C# can only convert strings to integers, and has a multitude of different build in functions, that are supposed to domething else, but does just that.
And I could invent a deep platter for my soup and hot water for my badth...
Rafnas T PPosted Mar 20, 2017, 8:57 AM
Birger SørensenPosted Mar 20, 2017, 8:49 AM
Have tried float and Singe as well. Visual Studios version of C#, does not seem to accept float - it points to definition of type Single.
Which actually is why I decided on double, as float would/should be adequate.....
Birger SørensenPosted Mar 20, 2017, 8:22 AM
I do like this:
Person.Height = double.Parse(ParseFileText("height", source, len));
// double.TryParse(ParseFileText("height", source, len), out Girl.Height);
// Person.Height = Convert.ToDouble(ParseFileText("height", source, len));
Which in turn is why I ask here ....
(I did try again, after you saying it is not possible - but it still does not do as you tell it to)
weight and year of birth are otheres - these are integers, that come out right.
private String ParseFileText(String param, String source, int len)
{
String ret = "";
int beg = source.IndexOf(param + ">", len) + 1 + param.Length;
int lgt = source.IndexOf("" + param, len) - beg;
if (lgt > 0) { ret = source.Substring(beg, lgt); }<= debugging, ret is "5.58", "5.41", "5.84" ...
return ret;
}
private String ParseFileText(String param, String source, int len)
{
int beg = source.IndexOf(param + ">", len) + 1 + param.Length;
int lgt = source.IndexOf("" + param, len) - beg;
return (lgt > 0) ? source.Substring(beg, lgt) : "";
}
Which not surprisingly gives the exact same erroneous results in struct Person.
Rafnas T PPosted Mar 20, 2017, 6:41 AM
Vaibhav DeshmukhPosted Mar 20, 2017, 5:40 AM
Nitin SontakkePosted Mar 20, 2017, 5:25 AM