round
주어진 값을 주어진 자리 아래에서 반올림 하여 반환
Returns the rounded value of val to specified precision
echo round(1.95583, 2); // 1.96?>
문제> round 를 사용하지 않고 위와 동일한 문제에 동일한 답이 나오도록 처리하세요.
제한시간 - 2시간
댓글 16개
14년 전
ㅠㅠ 저만 풀면 좀 그런거 같은데
14년 전
어때요.... 다 같은 답이 나오는 것도 아니고 ..
그냥 풀면 됩니다.
그냥 풀면 됩니다.
14년 전
디자이너로써 그냥>>
if 소수점 3자리째의 수가 5이상이면 2자리수에 +1시켜서 두자리수 까지만 출력해라.
else 이면 그냥 소수점두자리수까지만 표현해라.
라고 답글달아봅니다 ㅋ
if 소수점 3자리째의 수가 5이상이면 2자리수에 +1시켜서 두자리수 까지만 출력해라.
else 이면 그냥 소수점두자리수까지만 표현해라.
라고 답글달아봅니다 ㅋ
JMoon
14년 전
echo "1.96";
ㅋㅅㅋ......
ㅋㅅㅋ......
14년 전
이건 쉽네요... ((int)1.95583 * (10 ^ 2) +9))/ 100)
14년 전
echo xround(1.95583, 2);
function xround($rtn,$slength) {
$temp=1;
for ($i=1; $i<=$slength; $i++) $temp=$temp*10;
$rtn=$rtn*$temp+0.5;
return ((int) $rtn/$temp );
}
검사는 안해봣음 --; 대충 맞을것 같음
---> 검사해봄 잘됨
function xround($rtn,$slength) {
$temp=1;
for ($i=1; $i<=$slength; $i++) $temp=$temp*10;
$rtn=$rtn*$temp+0.5;
return ((int) $rtn/$temp );
}
검사는 안해봣음 --; 대충 맞을것 같음
---> 검사해봄 잘됨
14년 전
제한시간도 생겼네요 ㅠㅠ
최대한 네이티브로 했는데 is_numeric 은 예외처리로 끼워넣은거니까 봐주세요.
function round_custom($num,$pos=1){
if((int)$pos < 0) return 0;
if(is_numeric($num) == FALSE){
return 0;
}
$pos_helper = 1;
for($i = 0;$i<$pos;$i++){
$pos_helper*=10;
}
$constant_int_helper = 10;
$temp_var1 = (int)(($num*$pos_helper*$constant_int_helper + (($num*$pos_helper*$constant_int_helper)%10>4?10:-10))/$constant_int_helper)/$pos_helper;
return $temp_var1;
}
최대한 네이티브로 했는데 is_numeric 은 예외처리로 끼워넣은거니까 봐주세요.
function round_custom($num,$pos=1){
if((int)$pos < 0) return 0;
if(is_numeric($num) == FALSE){
return 0;
}
$pos_helper = 1;
for($i = 0;$i<$pos;$i++){
$pos_helper*=10;
}
$constant_int_helper = 10;
$temp_var1 = (int)(($num*$pos_helper*$constant_int_helper + (($num*$pos_helper*$constant_int_helper)%10>4?10:-10))/$constant_int_helper)/$pos_helper;
return $temp_var1;
}
14년 전
echo ((int)((1.95583 * 100) + .9)) / 100;
14년 전
echo (int)((1.95583 + 0.005) * 100) / 100;
14년 전
function banOlim($num, $r){
$roundingplace = pow(10,$r);
$num = $num*$roundingplace;
$num = ceil($num);
return $num / $roundingplace;
}
echo banOlim(1.95583, 2);
$roundingplace = pow(10,$r);
$num = $num*$roundingplace;
$num = ceil($num);
return $num / $roundingplace;
}
echo banOlim(1.95583, 2);
14년 전
pow라는 함수가 있군요..... 허허~! 몰라서 for문 돌림 --;
ceil 은 반올림이 아닌것으로 이상합니다만.
banOlim(1.95583, 4) 해보시면 올림으로 나옵니다.
ceil 은 반올림이 아닌것으로 이상합니다만.
banOlim(1.95583, 4) 해보시면 올림으로 나옵니다.
14년 전
<?
function xround($float, $precision=0) {
$num = pow(10, $precision);
return (int)(($float + (0.5 / $num)) * $num) / $num;
}
echo xround(1.95583, 2);
function xround($float, $precision=0) {
$num = pow(10, $precision);
return (int)(($float + (0.5 / $num)) * $num) / $num;
}
echo xround(1.95583, 2);
14년 전
echo number_format(1.95583, 2);
14년 전
WoW !!!
14년 전
printf("%0.2f", 1.95583);
오리궁대짝
14년 전
sprintf("%01.2f", 1.95583);
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7630 | 10년 전 | 647 | ||
| 7629 |
|
10년 전 | 2376 | |
| 7628 | 10년 전 | 784 | ||
| 7627 |
|
10년 전 | 1017 | |
| 7626 |
|
10년 전 | 1782 | |
| 7625 | 10년 전 | 689 | ||
| 7624 | 10년 전 | 706 | ||
| 7623 |
|
10년 전 | 3071 | |
| 7622 | 10년 전 | 718 | ||
| 7621 |
leeleeleelee
|
10년 전 | 580 | |
| 7620 | 10년 전 | 536 | ||
| 7619 | 10년 전 | 477 | ||
| 7618 | 10년 전 | 1009 | ||
| 7617 | 10년 전 | 720 | ||
| 7616 | 10년 전 | 629 | ||
| 7615 | 10년 전 | 725 | ||
| 7614 | 10년 전 | 1250 | ||
| 7613 |
|
10년 전 | 2079 | |
| 7612 | 10년 전 | 1133 | ||
| 7611 | 10년 전 | 1401 | ||
| 7610 |
|
10년 전 | 1897 | |
| 7609 |
|
10년 전 | 1326 | |
| 7608 |
mwdkim
|
10년 전 | 1121 | |
| 7607 |
|
10년 전 | 1046 | |
| 7606 |
mwdkim
|
10년 전 | 3917 | |
| 7605 | 10년 전 | 685 | ||
| 7604 | 10년 전 | 1021 | ||
| 7603 | 10년 전 | 1644 | ||
| 7602 |
|
10년 전 | 1063 | |
| 7601 |
AniNest
|
10년 전 | 2781 | |
| 7600 |
port443
|
10년 전 | 1018 | |
| 7599 | 10년 전 | 939 | ||
| 7598 | 10년 전 | 1010 | ||
| 7597 | 10년 전 | 4566 | ||
| 7596 |
SeungYeon
|
10년 전 | 884 | |
| 7595 |
untitled
|
10년 전 | 2411 | |
| 7594 |
프로그래머7
|
10년 전 | 1718 | |
| 7593 |
untitled
|
10년 전 | 2357 | |
| 7592 |
untitled
|
10년 전 | 1929 | |
| 7591 |
untitled
|
10년 전 | 2673 | |
| 7590 |
아리마2001
|
10년 전 | 848 | |
| 7589 | 10년 전 | 1101 | ||
| 7588 |
|
10년 전 | 2910 | |
| 7587 | 10년 전 | 1300 | ||
| 7586 | 10년 전 | 663 | ||
| 7585 | 10년 전 | 1685 | ||
| 7584 | 10년 전 | 1404 | ||
| 7583 |
leeleeleelee
|
10년 전 | 1157 | |
| 7582 |
|
10년 전 | 1100 | |
| 7581 | 10년 전 | 1317 | ||
| 7580 | 10년 전 | 979 | ||
| 7579 |
|
10년 전 | 601 | |
| 7578 | 10년 전 | 1425 | ||
| 7577 |
|
10년 전 | 1867 | |
| 7576 | 10년 전 | 1381 | ||
| 7575 |
멋진남자임
|
10년 전 | 1458 | |
| 7574 | 10년 전 | 2113 | ||
| 7573 | 10년 전 | 3244 | ||
| 7572 | 10년 전 | 756 | ||
| 7571 |
|
10년 전 | 778 | |
| 7570 |
|
10년 전 | 1302 | |
| 7569 | 10년 전 | 1544 | ||
| 7568 |
this1mg
|
10년 전 | 1044 | |
| 7567 |
|
10년 전 | 754 | |
| 7566 | 10년 전 | 914 | ||
| 7565 |
Angel하늘
|
10년 전 | 987 | |
| 7564 |
seoldi
|
10년 전 | 1225 | |
| 7563 |
|
10년 전 | 1363 | |
| 7562 |
멋진남자임
|
10년 전 | 2075 | |
| 7561 | 10년 전 | 703 | ||
| 7560 |
leeleeleelee
|
10년 전 | 893 | |
| 7559 | 10년 전 | 5033 | ||
| 7558 |
RinaP
|
10년 전 | 771 | |
| 7557 |
|
10년 전 | 1233 | |
| 7556 | 10년 전 | 1186 | ||
| 7555 |
hyohyojj1234
|
10년 전 | 1654 | |
| 7554 | 10년 전 | 1088 | ||
| 7553 |
senseme
|
10년 전 | 1333 | |
| 7552 |
ehdltdoit
|
10년 전 | 1430 | |
| 7551 |
|
10년 전 | 1814 | |
| 7550 |
leeleeleelee
|
10년 전 | 1582 | |
| 7549 | 10년 전 | 2416 | ||
| 7548 | 10년 전 | 1835 | ||
| 7547 |
멋진남자임
|
10년 전 | 1956 | |
| 7546 | 10년 전 | 998 | ||
| 7545 |
ILMare1003
|
10년 전 | 1275 | |
| 7544 |
|
10년 전 | 1240 | |
| 7543 | 10년 전 | 879 | ||
| 7542 | 10년 전 | 651 | ||
| 7541 |
울라라라우
|
10년 전 | 859 | |
| 7540 | 10년 전 | 1595 | ||
| 7539 | 10년 전 | 924 | ||
| 7538 |
|
10년 전 | 1827 | |
| 7537 | 10년 전 | 3606 | ||
| 7536 |
Gaumi
|
10년 전 | 1404 | |
| 7535 |
프로그램은어려워
|
10년 전 | 1260 | |
| 7534 |
senseme
|
10년 전 | 1201 | |
| 7533 | 10년 전 | 1188 | ||
| 7532 | 10년 전 | 852 | ||
| 7531 | 10년 전 | 2043 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기