0
How do I multiply 2 int values that contain a decimal?
I am multiplying 2 int values 1.10 * 100 but it gives me 100 as the answer instead of 110. It's ignoring the. 10 How can I get the 110 value returned
6 Answers
+ 5
1.10 isn't a int value. Can you shows the code(if any) you have written so far .
Also please write the language name in tags that is relevant to the code or the question .
+ 1
Isang-Ofon Udo-Arthur
Give this a go, replace what you have inside your Increase method:
x += (int)(x * (y/100.0));
For 100 budget, 10 percent. This works like:
100 + (100 * (10 / 100))
Or
100 + (100 * 0.1)
In the division Iâve added .0 to make the division result a double. If you divide two ints in c# the result is an int. If one operand is a floating point number so is the result. You could have explicitly casted y as a double. Either works.
With this part: x * (y/100.0)
because we are multiplying a floating point number, the result is also a float. We explicitly cast to int by using (int) before adding (+=) to the original value.
0
It's actually one of the C# exercises that I am stuck on. Check it out below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int salaryBudget = Convert.ToInt32(Console.ReadLine());
int percent = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Before the increase: " + salaryBudget);
//complete the method call
Increase(ref salaryBudget, ref percent);
Console.WriteLine("After the increase: " + salaryBudget);
}
//complete the method
static void Increase(ref int x, ref int y)
{
x = ((y/100)+1) * x;
}
}
}
0
Thank you.. This worked.
0
Thank you DavX