함수 floor()

1 개요[ | ]

floor
  • "Round fractions down"
  • 버림 함수

2 C[ | ]

#include<stdio.h>
#include<math.h>

int main() {
    printf("%f", floor(3.14159)); // 3.000000
    printf("%f", floor(-3.14159)); // -4.000000
    printf("%f", floor(9.98)); // 9.000000
}

3 C++[ | ]

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
  cout << floor(3.14159) << endl; // 3
  cout << floor(-3.14159) << endl; // -4
  cout << floor(9.98) << endl; // 9
}
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
  cout << floor(3.14159) << endl; // 3
  cout << floor(-3.14159) << endl; // -4
  cout << floor(9.98) << endl; // 9
}
#include <iostream>
int main() {
    float f = 123.456;
    float res = (int)(f*100.0)/100.0;
    std::cout << res << std::endl;
    // 123.45
}

4 EXCEL[ | ]

=INT(3.14159)
// returns 3

=INT(-3.14159)
// returns -4

=INT(9.98)
// returns 9
=FLOOR(3.14159, 1)
// returns 3

=FLOOR(-3.14159, -1)
// returns -3

=FLOOR(9.98, 1)
// returns 9

5 JavaScript[ | ]

console.log( Math.floor(10.6) ); // 10

6 PHP[ | ]

echo floor(3.14159);   // 3
echo floor(-3.14159); // -4
echo floor(9.98); // 9

7 Python[ | ]

import math
print( math.floor(3.14) ) # 3
print( math.floor(2.72) ) # 2
print( math.floor(-3.14) ) # -4
print( math.floor(-2.72) ) # -3

8 Perl[ | ]

use POSIX;
print floor(9.98);
# 9

9 SQL[ | ]

9.1 Oracle[ | ]

SELECT FLOOR(12.3456) FROM DUAL;
-- returns 12

SELECT FLOOR(-12.3456) FROM DUAL;
-- returns -13
SELECT TRUNC(12.3456) FROM DUAL;
-- returns 12

SELECT TRUNC(-12.3456) FROM DUAL;
-- retruns -12

10 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}