5 Replies - 424 Views - Last Post: 05 October 2012 - 03:27 AM Rate Topic: -----

#1 krakatoa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 04-October 12

Calculations

Posted 05 October 2012 - 02:07 AM

Hello. I have a problem displaying double values, it removes 0 in front. For example answer should be 0.14 and it gives me 141.37.
Is This A Good Question/Topic? 0
  • +

Replies To: Calculations

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Calculations

Posted 05 October 2012 - 02:28 AM

Without seeing your code it's impossible to tell what's wrong. Sure we could throw guesses but that's not worth it.
Was This Post Helpful? 1
  • +
  • -

#3 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2134
  • View blog
  • Posts: 3,272
  • Joined: 21-June 11

Re: Calculations

Posted 05 October 2012 - 02:32 AM

If it just cut off "0.", the result would be 14137, not 141.37, right (assuming the number in question was really 0.14137 - not just 0.14)? It looks more like the result got multiplied by 1000 somewhere.

But as Janne_panne said, it's impossible for us to tell you how that happened without seeing your code.
Was This Post Helpful? 0
  • +
  • -

#4 krakatoa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 04-October 12

Re: Calculations

Posted 05 October 2012 - 03:07 AM

For example
      
        private void button1_Click(object sender, EventArgs e)
        {
            double x = Convert.ToDouble(textBox1.Text);
            double y = Convert.ToDouble(textBox2.Text);
            textBox3.Text = Convert.ToString(x+y);
        }


0.6 + 0.5 i am getting 11
Was This Post Helpful? 0
  • +
  • -

#5 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2134
  • View blog
  • Posts: 3,272
  • Joined: 21-June 11

Re: Calculations

Posted 05 October 2012 - 03:23 AM

So you enter 0.6 and 0.5 in textBox1 and textBox2 respectively? What's your system's locale?

Conversions to and from strings are locale-sensitive by default. If your system's locale that uses commas instead of dots as the decimal separator, you'll need to enter the numbers as 0,6 and 0,5 or you'll need to tell the conversion methods to use a different locale.
Was This Post Helpful? 1
  • +
  • -

#6 krakatoa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 04-October 12

Re: Calculations

Posted 05 October 2012 - 03:27 AM

Thanks, with "," it works :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1