Questions tagged [floor]

A function common to many programming languages that returns the next lowest integer value by rounding the value down if necessary.

Returns the next lowest integer value by rounding down value if necessary. php.net

Examples

echo floor(1.3);    // returns   1
echo floor(10.9);   // returns  10
echo floor(-3.14);  // returns  -4
365 questions
-2
votes
2 answers

Why floor and ceil value giving different values for an integer in c++

Below is the program I've written to find the exponent of 6, but I this its giving wrong output or I may be wrong somewhere, I'm unable to figure out here. #include using namespace std; #define ll long long int main() { ll t; …
aksr
  • 272
  • 2
  • 11
-2
votes
2 answers

Order of operation and How does the random() play in this scenario

Just started learning loops and I'm having trouble understanding the order of operation here in the let value, along with how the random() works in this scenario. From what it looks like: Math.floor() prevents decimals and Math.random() selects a…
Shulkin
  • 17
  • 5
-2
votes
2 answers

Why does floor() return value less by 1?

I'm doing some calculation in PHP using floor() method and find out this. Code: "); echo(69950.40-10670.40); ?> Output: 59279 59280 Note: I want it to be 59280 even after floor(). I don't know why…
Arun J
  • 691
  • 4
  • 13
  • 24
-2
votes
1 answer

outputting the middle element(s) of matrices in R

I'm really stuck on this problem: Please help. Create a code that takes a matrix as an input and outputs the middle element of the matrix. (hint: think about floor and ceiling functions)
cate
  • 11
-2
votes
2 answers

Simplify function with Math.pow() and Math.floor() calls inside a loop

How can I simplify the following function and the repeated calls to Math.pow()? function x(a, b, c) { rv = Math.floor(a * Math.pow(2, b)); for (i = 1; i < c; i++) { rv += Math.floor(a * Math.pow(1.2, b + i)); } return…
-2
votes
1 answer

Rounding down a floating point number to an integer value without a floor function in C

I need to write a function in C that rounds down a floating point number to an integer. For example, 10.6 becomes 10. 22.1249 becomes 22. However, I can't use a floor function. Can this be done?
Data
  • 483
  • 4
  • 20
-2
votes
1 answer

Rounding off floating point value in C++ without using build in functions

I think truncating can be done by converting float to int e.g 25.83f will be 25 when converted to int but it should be 26 when rounded off..how this can be achieved please help me thanks Similarly I think ceiling can be done by converting to int…
Awais Nasir
  • 679
  • 10
  • 14
-2
votes
2 answers

Javascript: Where do I put Math.floor(Math.random)?

Okay, I'm obviously an extreme newbie, so be gentle. As I'm learning Javascript, I'm creating a quiz to better help me retain and practice the information. The following is a sample of my code so far(the actual array has been shortened for this…
-2
votes
3 answers

c# equivalent of the c++ "floor" function

I'm looking for an implementation of floor(x) in C# so that it would match the C++ version. floor of 2.3 is 2.0 floor of 3.8 is 3.0 floor of -2.3 is -3.0 floor of -3.8 is -4.0 Since a C++ reviewer will be checking my code, what implementation of…
halfbit
  • 54,462
  • 46
  • 195
  • 426
-3
votes
2 answers

error during calculation multiple textboxes

i found a error System.FormatException: 'Input string was not in a correct format.' in my c# project. i want to convert my decimal value to round but if value is "7.99" it's output is 7 only which is at "b". i use this function but i failed. void…
R.Soomro
  • 1
  • 4
-3
votes
1 answer

JAVA - double issue - ceil and floor functions

I need to solve the issue related to the double representation. For example, I have the following set of values: id: 1 val: 8.11 floor: 8.109999 ceil: 8.11 id: 2 val: 8.31 floor: 8.31 ceil: 8.310001 id: 3 val: 8.27 …
Fab
  • 919
  • 4
  • 17
  • 29
-3
votes
2 answers

Shorten double value x digit

I have a double value and I want to shorten it to 6 digits after the integer part. For example: double aDouble = 418.73684210526318; double convertedDouble = conversion (aDouble); convertedDouble must be 418.736842 I implemented this…
Anamort
  • 321
  • 4
  • 14
-3
votes
2 answers

The output of ceil() and floor() in C language is odd

I am doing my homework to realize a C programe and during my work there is one step that I need to get the interger part of the double type numbers. So I choose ceil() or floor() in to realize this. But the output is unpredictable and far from…
sikisis
  • 428
  • 6
  • 18
-3
votes
2 answers

using Math.Floor

I am trying to use the Math.Floor method on 2 user-input numbers but whenever I try to use the Math.Floor with my input3 and input3a it just doesn't work. I've seen examples for already set numbers such as in an array but not of numbers that the…
Mh_Shiro
  • 11
  • 2
-3
votes
1 answer

Most significant decimal digit (or 0.3 - 0.1 = 0.1 )

This operation should return 2, but it returns 1 instead because of the floating point representation: a <- .3 b <- .1 floor((a-b)*10) I basically want the first digit after the point, of the actual base-10 result, not the floating-point computer's…
Julián Urbano
  • 8,100
  • 1
  • 28
  • 51
1 2 3
24
25