Are you good with Maths API
-
I wonder if u can help me in solving the following problem: I want to divide a number by 10 and get the result as the highest number. Let me explain with following examples: 13/10 = 2 and 27/10 = 3 How can I achieve this thanks
-
I wonder if u can help me in solving the following problem: I want to divide a number by 10 and get the result as the highest number. Let me explain with following examples: 13/10 = 2 and 27/10 = 3 How can I achieve this thanks
Math.Round( (a / 10) + .5 )
? David -
I wonder if u can help me in solving the following problem: I want to divide a number by 10 and get the result as the highest number. Let me explain with following examples: 13/10 = 2 and 27/10 = 3 How can I achieve this thanks
How about
(int)((n+9)/10)
? You can even skip the(int)
if your n already is an int... mav -
I wonder if u can help me in solving the following problem: I want to divide a number by 10 and get the result as the highest number. Let me explain with following examples: 13/10 = 2 and 27/10 = 3 How can I achieve this thanks
Not knowing C# I can't give you the proper code, but in pseudo-code: If (x - int(x)) > 0.00 return int(x) + 1 else return int(x) Unlike the rounding function, which will round down as well as up, this will return either the original input, if it is an integer, or the next higher integer if it contains any fractional part at all. You may still get some goofy errors, though, because the input might have some small fractional part due to previous calculations. There are ways to get around that, but they may not be necessary depending upon your application. "...putting all your eggs in one basket along with your bowling ball and gym clothes only gets you scrambled eggs and an extra laundry day... " - Jeffry J. Brickley
-
I wonder if u can help me in solving the following problem: I want to divide a number by 10 and get the result as the highest number. Let me explain with following examples: 13/10 = 2 and 27/10 = 3 How can I achieve this thanks
-
I wonder if u can help me in solving the following problem: I want to divide a number by 10 and get the result as the highest number. Let me explain with following examples: 13/10 = 2 and 27/10 = 3 How can I achieve this thanks
gee *cough* I'll join, assuming x is an int..
int n = (x / 10) + (x % 10 > 0 ? 1 : 0);
*lame around* \o/ -
gee *cough* I'll join, assuming x is an int..
int n = (x / 10) + (x % 10 > 0 ? 1 : 0);
*lame around* \o/While walking at the abyss of insanity, I found out, you can use something completely senseless, far away from anything that could be called useful. Evalute strings.
int x = 27; int n = 0; string seperator = System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator; double d = ((double)x / 10.0d); string s = d.ToString("F1"); if (!s.Substring(s.IndexOf(seperator) + 1, 1).Equals("0")) { d += 1.0d; s = d.ToString("F1"); } n = int.Parse(s.Substring(0, s.IndexOf(seperator)));
-
While walking at the abyss of insanity, I found out, you can use something completely senseless, far away from anything that could be called useful. Evalute strings.
int x = 27; int n = 0; string seperator = System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator; double d = ((double)x / 10.0d); string s = d.ToString("F1"); if (!s.Substring(s.IndexOf(seperator) + 1, 1).Equals("0")) { d += 1.0d; s = d.ToString("F1"); } n = int.Parse(s.Substring(0, s.IndexOf(seperator)));
Daniel, you frighten me! ;) mav
-
While walking at the abyss of insanity, I found out, you can use something completely senseless, far away from anything that could be called useful. Evalute strings.
int x = 27; int n = 0; string seperator = System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator; double d = ((double)x / 10.0d); string s = d.ToString("F1"); if (!s.Substring(s.IndexOf(seperator) + 1, 1).Equals("0")) { d += 1.0d; s = d.ToString("F1"); } n = int.Parse(s.Substring(0, s.IndexOf(seperator)));
You are outta control! ;P
-
I wonder if u can help me in solving the following problem: I want to divide a number by 10 and get the result as the highest number. Let me explain with following examples: 13/10 = 2 and 27/10 = 3 How can I achieve this thanks
Wouldn't this be machinecode optimised: n >> 1; n /= 5; n++; In asm it would be like: ;number in AL SHL AL,1 ;2 clocks MOV BL, 5 ;4 clocks DIV BL ;0-90 clocks INC AX ;2 clocks (saved one clock by using AX insted of AL...) ; ;I'm not familiar with how much the div instruction takes in time but ;since it is only 5 I think's it's not much. ; The PROgrammer Niklas Ulvinge aka IDK
-
While walking at the abyss of insanity, I found out, you can use something completely senseless, far away from anything that could be called useful. Evalute strings.
int x = 27; int n = 0; string seperator = System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator; double d = ((double)x / 10.0d); string s = d.ToString("F1"); if (!s.Substring(s.IndexOf(seperator) + 1, 1).Equals("0")) { d += 1.0d; s = d.ToString("F1"); } n = int.Parse(s.Substring(0, s.IndexOf(seperator)));
Umm.. yes, I got it out of the abyss of insanity, I'm walking quite close to it but usually don't use anything from there :D Even if it works, it's awful, but it works :D I also like the ASM version from Niklas Ulvinge :)
-
I wonder if u can help me in solving the following problem: I want to divide a number by 10 and get the result as the highest number. Let me explain with following examples: 13/10 = 2 and 27/10 = 3 How can I achieve this thanks
Thanks for many ideas. This is what worked for me: Math.Ceiling(13.0D / 10.0D); Only if the values inside Ceiling(...) are Double and not int