Résolu Problème de conversion de String en Decimal

Wazyx YT

Youtuber et Glitcher
Premium
Inscription
2 Février 2014
Messages
793
Réactions
681
Points
6 096
Alors voilà j'essaie de créer une appli pour connaitre le cours du Bitcoin en € sauf que j'ai une erreur à la ligne ou j'ai ma note..
Code:
private void button2_Click(object sender, EventArgs e)
        {
            WebClient BTCToEur = new WebClient();
            string BTCValue1 = BTCToEur.DownloadString("https://blockchain.info/tobtc?currency=EUR&value=1");
            decimal BTCDecimal = System.Convert.ToDecimal(BTCValue1); // le problème est que je souhaite passer de string en Decimal pour effectuer un opération
            BTCDecimal = 1 / BTCDecimal;
            string BTCValue2 = BTCDecimal.ToString();
            label5.Text = BTCValue2 + " €";
        }
 

ChuteAa ©

Chacun sa croix !!
Premium
Inscription
3 Décembre 2013
Messages
1 890
Réactions
1 204
Points
13 998
Alors voilà j'essaie de créer une appli pour connaitre le cours du Bitcoin en € sauf que j'ai une erreur à la ligne ou j'ai ma note..
Code:
private void button2_Click(object sender, EventArgs e)
        {
            WebClient BTCToEur = new WebClient();
            string BTCValue1 = BTCToEur.DownloadString("https://blockchain.info/tobtc?currency=EUR&value=1");
            decimal BTCDecimal = System.Convert.ToDecimal(BTCValue1); // le problème est que je souhaite passer de string en Decimal pour effectuer un opération
            BTCDecimal = 1 / BTCDecimal;
            string BTCValue2 = BTCDecimal.ToString();
            label5.Text = BTCValue2 + " €";
        }
Code:
WebClient BTCToEur = new WebClient();
            string BTCValue1 = BTCToEur.DownloadString("https://blockchain.info/tobtc?currency=EUR&value=1");
            System.Globalization.NumberFormatInfo provider = new System.Globalization.NumberFormatInfo();
            provider.NumberDecimalSeparator = ",";
            provider.NumberGroupSeparator = ".";
            decimal BTCDecimal = System.Convert.ToDecimal(BTCValue1 , provider); // le problème est que je souhaite passer de string en Decimal pour effectuer un opération
            BTCDecimal = 1 / BTCDecimal;
            string BTCValue2 = BTCDecimal.ToString();
            label5.Text = BTCValue2 + " €";
 

Wazyx YT

Youtuber et Glitcher
Premium
Inscription
2 Février 2014
Messages
793
Réactions
681
Points
6 096
J'ai au final fais ça
Code:
WebClient BTCToEur = new WebClient();
            string BTCValue1 = BTCToEur.DownloadString("https://blockchain.info/tobtc?currency=EUR&value=1");
            decimal BTCDecimal = decimal.Parse(BTCValue1, System.Globalization.CultureInfo.InvariantCulture);
            BTCDecimal = 1 / BTCDecimal;
            string BTCValue2 = BTCDecimal.ToString("0.0");
            label5.Text = BTCValue2 + " €";
 
Haut