-1

I take data from four different pages and different domains.

1- .com

2- .co.uk

3- .ca

4- .co.jp

For all of the above i take number from Html and Convert them to Double using line:

string  lowestSellerPrice = (Convert.ToDouble(fbalPrice) + 
                             Convert.ToDouble(fbalsPrice)).ToString();

This works perfectly fine for the first 3 domains but for .co.jp even though there is always a number in fbalPrice and fbalsPrice it is always giving exception :

Input string was not in a correct format

Any suggestion as i have been struggling with this for too long now no result i also tried the try parse solution but no luck.

UPDATE:

See this:

enter image description here

confusedMind
  • 2,573
  • 7
  • 33
  • 74
  • " even though there is always a number in fbalPrice and fbalsPrice" , are you sure there is nothing else than numbers in your string ? Use a debugger, see what exactly is the value of `fbalPrice` – Habib Sep 05 '14 at 13:08
  • 2
    What is the exact content of `fbalPrice` and `fbalsPrice` when it throws the error? – DavidG Sep 05 '14 at 13:09
  • 2400 and 1200 that is what is the issue always a number...also to mention in case of .co.jp when i reach this line even if i manually put the numbers in there to check if there is something different with number in japanese maybe still i get the error so no matter what i do i get the exception – confusedMind Sep 05 '14 at 13:09
  • Forget not, the hidden invisible character... I mean, you're talking about .jp, what are the odds of having an unknown invisible japanese character in your console output? HUGE – Kilazur Sep 05 '14 at 13:11
  • 1
    Just try `string fbalPrice = "2400"; double d = Convert.ToDouble(fbalPrice);`, This would never throw the exception, Put a debug point, examine `fbalPrice` and `fbalsPrice` values. – Habib Sep 05 '14 at 13:12
  • @RobEpstein Read the question he already said that he has tried TryParse... – Syed Farjad Zia Zaidi Sep 05 '14 at 13:13
  • @Habib tried everything thing yes i think that might be the case as there is a space at the end i used Trim() it wont end so i manually did Replace(" ","") and it works but the time it reaches that line there is always only number still exception – confusedMind Sep 05 '14 at 13:14
  • Have you tried using the japanese culture with `Double.TryParse` as in `double.TryParse(fbalPrice, CultureInfo.GetCultureInfo("ja-JP"))`? – Daniel J.G. Sep 05 '14 at 13:16
  • @DanielJ.G. havent tried that let me check. – confusedMind Sep 05 '14 at 13:16
  • Btw why a downvote what is wrong with my question? – confusedMind Sep 05 '14 at 13:17
  • There may be a non-printable character in there, as in [this case](http://stackoverflow.com/questions/25403588/jsonserializer-deserialize-not-working-properly-for-unicode-characters-in-c-shar/25403869#comment39625289_25403869). Ensure the text contains only numeric characters with a Regex – Panagiotis Kanavos Sep 05 '14 at 13:20
  • @DanielJ.G. just tried it changes everything to 0.0 no exception though. – confusedMind Sep 05 '14 at 13:26
  • updated the question for all to see the values , so you can see there is only number – confusedMind Sep 05 '14 at 13:31
  • That `jp` looks suspicions. Do they (Japanese guys) use *digits* to represent numbers? Try to use [`double.Parse(fbalPrice, NumberFormatInfo.InvariantInfo)`](http://msdn.microsoft.com/en-us/library/t9ebt447.aspx). – Sinatr Sep 05 '14 at 14:07
  • @Sinatr same exception .... – confusedMind Sep 05 '14 at 14:32
  • Okz i solved it , looks stupid actually... – confusedMind Sep 05 '14 at 14:45

1 Answers1

0

I solved it like this :

The string were like " 1234" and " 111" and i then did Replace(" ",""); . And only number lift this however did not work so i did this:

 if (fbalPrice.Contains(" "))
     {
     fbalPrice = fbalPrice.Remove(0, fbalPrice.IndexOf(" ") + 1).Replace(",","").Trim();
     }
 if(fbalsPrice.Contains(" "))
     {
     fbalsPrice = fbalsPrice.Remove(0, fbalsPrice.IndexOf(" ") + 1).Replace(",", "").Trim();
     }

And then added them and it worked.

confusedMind
  • 2,573
  • 7
  • 33
  • 74