I can’t use floor function in my project.
What is problem?
int numAllSms = Math.Floor( (msg4SmsPart1.Count()) / 69) + Math.Floor((msg4SmsPart2.Count()) / 69) ;
My string is :
String msg4SmsPart1 = "", msg4SmsPart2 = "" ;
It's my error: "The call is ambiguous between the following methods or properties: 'System.Math.Floor(decimal)' and 'System.Math.Floor(double)'"
You have at least two problems:
Math.Floor
will return a double
or decimal
; you're trying to assign it to an int
variableMath.Floor
.I suspect you want:
int numAllSms = (int) (Math.Floor(msg4SmsPart1.Count() / 69.0) +
Math.Floor((msg4SmsPart2.Count() / 69.0));
Note the use of 69.0
instead of 69
so that it's a double
literal, leading to floating point division.
It's not clear whether you actually want Floor
or Ceiling
though - I would have expected Ceiling
to be more appropriate in this case. As noted in p.s.w.g's answer, you can just use integer arithmetic for all of this - if you want the Ceiling
equivalent, you can use:
int numAllSms = (msg4SmsPart1.Count() + 68) / 69
+ (msg4SmsPart1.Count() + 68) / 69;
Adding 68 before the division makes it effectively round any non-integer result up.
See more on this question at Stackoverflow