# Calculator Not Returning Decimal Values

Page 1 of 1

## 3 Replies - 454 Views - Last Post: 05 December 2012 - 07:41 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=302772&amp;s=6767abdd0594cd109445e4ebf45d5d34&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 HPLG

Reputation: 0
• Posts: 5
• Joined: 06-November 12

# Calculator Not Returning Decimal Values

Posted 04 December 2012 - 06:50 PM

My calculator is not returning decimal values for example if I do 2.2 + 2.2 the answer it returns is 44 instead of 4.4??
What did I do wrong???
Here's my Code
```namespace CalcW
{
public class Calculator
{

public decimal CurrentValue { get; set;}

private decimal First{get;set;}
private decimal Second{get;set;}

public void EnterValue(decimal value, bool n )
{
if (n)
{
First = value;
}
else
{
Second=value;
}

}

{
CurrentValue = First + Second;
//CurrentValue + value;
}

public void Subtract()
{
CurrentValue = First - Second;
//CurrentValue - value;
}

public void Multiple()
{
CurrentValue = First * Second;
//CurrentValue * value;
}

public void Divide()
{
CurrentValue =First/Second;
//CurrentValue /= value;
}

public decimal Equals(decimal value, string sn)
{
this.EnterValue(value, false);

switch(sn)
{
case "+/-": Reciprocal(); break;
case "-": Subtract(); break;
case "*": Multiple(); break;
case "/": Divide(); break;
case "sqrt": SquareRoot(); break;
case "1/x": Fraction(); break;

}
First = 0;
Second = 0;
return CurrentValue;
}

public void Reciprocal()
{
CurrentValue =First *(-1);
}

public void SquareRoot()
{

}

public void Clear()
{
CurrentValue = 0;
}

public void Fraction()
{
CurrentValue = 1/First;
}

}
}
```

Is This A Good Question/Topic? 0

## Replies To: Calculator Not Returning Decimal Values

### #2 Skydiver

• Code herder

Reputation: 4029
• Posts: 12,856
• Joined: 05-May 12

## Re: Calculator Not Returning Decimal Values

Posted 04 December 2012 - 06:57 PM

If you set a breakpoint on line 70, what is the value of CurrentValue?

On first glance, the code looks correct. I think the issue maybe with your display code rather than your computation.

This post has been edited by Skydiver: 04 December 2012 - 06:58 PM

### #3 raghav.naganathan

• Perfectly Squared ;)

Reputation: 410
• Posts: 1,440
• Joined: 14-September 12

## Re: Calculator Not Returning Decimal Values

Posted 05 December 2012 - 07:24 AM

One logical thing I would like to point out here.

Reciprocal of a number is written as 1/(that number) and not number* (-1)

Eg.Reciprocal of 4 is 1/4

regards,
Raghav

### #4 tlhIn`toq

• Not here as much anymore

Reputation: 5977
• Posts: 13,078
• Joined: 02-June 10

## Re: Calculator Not Returning Decimal Values

Posted 05 December 2012 - 07:41 AM

Calculator tutorial