salimdeath
asked on
Rounding to the next whole number (E.g. 1.0124 becomes 2)
Hello Team,
I have got a special rounding to do and after many search performed in EE, i could not come across a solution. Can you please help me with the problem below;
After a calculation has been performed in my coding part, the result are displayed in a testbox. I DO NOT want the decimals to appear, all i need is that the result is rounded to the next whole number. The moment the value is over .0 something, it should be rounded to the next whole number. Please see example below;
Result being displayed ----> What i want to get
8.9 -------------------------- -----> 9
8.1 -------------------------- -----> 9
8.487 -------------------------- --> 9
8.091 -------------------------- --> 9
1.254 -------------------------- --> 2
1.014 -------------------------- --> 2
1.9745 -------------------------- -> 2
0.0021 -------------------------- -> 1
Looking ahead to hear your solutions team,
Thanks a lot for your help,
Kind regards.
Salim
I have got a special rounding to do and after many search performed in EE, i could not come across a solution. Can you please help me with the problem below;
After a calculation has been performed in my coding part, the result are displayed in a testbox. I DO NOT want the decimals to appear, all i need is that the result is rounded to the next whole number. The moment the value is over .0 something, it should be rounded to the next whole number. Please see example below;
Result being displayed ----> What i want to get
8.9 --------------------------
8.1 --------------------------
8.487 --------------------------
8.091 --------------------------
1.254 --------------------------
1.014 --------------------------
1.9745 --------------------------
0.0021 --------------------------
Looking ahead to hear your solutions team,
Thanks a lot for your help,
Kind regards.
Salim
ASKER
Hi Hongjun,
Thanks for replying.
I tried what you proposed, error displayed is "Expression Does not produce a Value". Here's my lines of codes that is displaying the decimals;
DataGridView1.Rows(0).Cell s("QtyReq" ).Value = (Convert.ToInt32(TxtQtyOrd er.Text) * Convert.ToInt32(TxtConeMet erage.Text )) / Convert.ToInt32(DVDGridYar nUse(0)("M eterage"))
Any other possible solutions ?
Thanks again for helping.
Thanks for replying.
I tried what you proposed, error displayed is "Expression Does not produce a Value". Here's my lines of codes that is displaying the decimals;
DataGridView1.Rows(0).Cell
Any other possible solutions ?
Thanks again for helping.
try this
DataGridView1.Rows(0).Cell s("QtyReq" ).Value = Math.Ceiling((Convert.ToIn t32(TxtQty Order.Text ) * Convert.ToInt32(TxtConeMet erage.Text )) / Convert.ToInt32(DVDGridYar nUse(0)("M eterage")) ).ToString ("0")
DataGridView1.Rows(0).Cell
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Hongjun,
Wow....... this one works like a charm !!! THANKS SO MUCH.
Beside of helping me with an appropriate solution, your response was very quick. I appreciate a lot.
Thanks again dude, you deserve the points.
Cheers.
Salim
PS: I got another issue on Date Calculation and Time Calculation. I hope you'll be around when i post it soon. Am not posting it now, cause i want to make sure that i searched everywhere.
Wow....... this one works like a charm !!! THANKS SO MUCH.
Beside of helping me with an appropriate solution, your response was very quick. I appreciate a lot.
Thanks again dude, you deserve the points.
Cheers.
Salim
PS: I got another issue on Date Calculation and Time Calculation. I hope you'll be around when i post it soon. Am not posting it now, cause i want to make sure that i searched everywhere.
:)
You can just customize it and then put it in your own code.
double d;
d = 8.0;
Console.WriteLine(Math.Cei
d = 8.2;
Console.WriteLine(Math.Cei
d = 8.9;
Console.WriteLine(Math.Cei
hongjun