'How to get double value when dividing an integer variable by a constant number in C#? [duplicate]
The followings are some parts of my code. I use the calcengine
library for doing mathematical operations in three textboxes. I want to get a rounded number in labelSTDW.Text
but the result is an integer. target1
has an integer value but target1/60
can have a double value. My problem is that labelSTDW.Text
. The text has always an integer value.
How can I solve this problem?
int target1, target2, target3;
double STDWorker, STDTechnician, STDExpert;
CalcEngine.CalcEngine CE = new CalcEngine.CalcEngine();
int.TryParse(CE.Evaluate(textBoxTLA.Text).ToString(), out target1);
int.TryParse(CE.Evaluate(textBoxTTE.Text).ToString(), out target2);
int.TryParse(CE.Evaluate(textBoxTEX.Text).ToString(), out target3);
TimeSpan timespanconversion = new TimeSpan(0, target1+target2+target3, 0);
labelTmin.Text = $"Total Time: {timespanconversion.Days}D-{timespanconversion.Hours}H:{timespanconversion.Minutes}m";
STDWorker = target1 / 60;
STDTechnician = target2 / 60;
STDExpert = target3 / 60;
labelSTDW.Text = $"Worker Work Time: {Math.Round(STDWorker, 2)}";
Solution 1:[1]
Before dividing by 60, convert target1
to double.
Convert.ToDouble(target1)/60
would give you double.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | gsb22 |