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);
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 3430 | 14년 전 | 1977 | ||
| 3429 | 14년 전 | 1398 | ||
| 3428 |
카프카07
|
14년 전 | 1870 | |
| 3427 | 14년 전 | 1503 | ||
| 3426 | 14년 전 | 1332 | ||
| 3425 | 14년 전 | 998 | ||
| 3424 | 14년 전 | 951 | ||
| 3423 | 14년 전 | 1174 | ||
| 3422 | 14년 전 | 1411 | ||
| 3421 | 14년 전 | 5942 | ||
| 3420 | 14년 전 | 1480 | ||
| 3419 | 14년 전 | 1194 | ||
| 3418 | 14년 전 | 1240 | ||
| 3417 | 14년 전 | 824 | ||
| 3416 | 14년 전 | 1003 | ||
| 3415 | 14년 전 | 1611 | ||
| 3414 |
elsarose
|
14년 전 | 1078 | |
| 3413 | 14년 전 | 740 | ||
| 3412 | 14년 전 | 1277 | ||
| 3411 | 14년 전 | 1342 | ||
| 3410 | 14년 전 | 1665 | ||
| 3409 | 14년 전 | 985 | ||
| 3408 | 14년 전 | 4563 | ||
| 3407 | 14년 전 | 1155 | ||
| 3406 | 14년 전 | 1127 | ||
| 3405 | 14년 전 | 1144 | ||
| 3404 | 14년 전 | 1345 | ||
| 3403 | 14년 전 | 1152 | ||
| 3402 |
네비플러스
|
14년 전 | 893 | |
| 3401 | 14년 전 | 966 | ||
| 3400 | 14년 전 | 1405 | ||
| 3399 | 14년 전 | 713 | ||
| 3398 | 14년 전 | 1286 | ||
| 3397 |
아이피마스터
|
14년 전 | 1275 | |
| 3396 | 14년 전 | 1363 | ||
| 3395 |
kimam
|
14년 전 | 4102 | |
| 3394 |
kimam
|
14년 전 | 1346 | |
| 3393 | 14년 전 | 1039 | ||
| 3392 | 14년 전 | 1466 | ||
| 3391 | 14년 전 | 1634 | ||
| 3390 |
|
14년 전 | 835 | |
| 3389 |
sooram
|
14년 전 | 2079 | |
| 3388 | 14년 전 | 2056 | ||
| 3387 | 14년 전 | 1644 | ||
| 3386 |
|
14년 전 | 1601 | |
| 3385 | 14년 전 | 1106 | ||
| 3384 | 14년 전 | 1596 | ||
| 3383 |
보헤미안7
|
14년 전 | 1526 | |
| 3382 | 14년 전 | 1233 | ||
| 3381 |
wldus
|
14년 전 | 965 | |
| 3380 |
wldus
|
14년 전 | 2707 | |
| 3379 | 14년 전 | 2019 | ||
| 3378 |
보헤미안7
|
14년 전 | 1381 | |
| 3377 | 14년 전 | 2032 | ||
| 3376 |
네비플러스
|
14년 전 | 913 | |
| 3375 | 14년 전 | 1018 | ||
| 3374 | 14년 전 | 1636 | ||
| 3373 | 14년 전 | 1742 | ||
| 3372 | 14년 전 | 1341 | ||
| 3371 |
호박둥구리
|
14년 전 | 1030 | |
| 3370 | 14년 전 | 1192 | ||
| 3369 |
열라바보숑
|
14년 전 | 1121 | |
| 3368 | 14년 전 | 1980 | ||
| 3367 | 14년 전 | 2107 | ||
| 3366 | 14년 전 | 1980 | ||
| 3365 | 14년 전 | 1114 | ||
| 3364 | 14년 전 | 1684 | ||
| 3363 | 14년 전 | 1742 | ||
| 3362 | 14년 전 | 1847 | ||
| 3361 |
|
14년 전 | 3628 | |
| 3360 |
호피무늬쫄티
|
14년 전 | 1172 | |
| 3359 |
|
14년 전 | 1959 | |
| 3358 |
DreamT
|
14년 전 | 888 | |
| 3357 | 14년 전 | 1014 | ||
| 3356 | 14년 전 | 857 | ||
| 3355 | 14년 전 | 1321 | ||
| 3354 |
sooram
|
14년 전 | 1773 | |
| 3353 | 14년 전 | 1312 | ||
| 3352 | 14년 전 | 1162 | ||
| 3351 | 14년 전 | 832 | ||
| 3350 | 14년 전 | 1806 | ||
| 3349 | 14년 전 | 1371 | ||
| 3348 | 14년 전 | 927 | ||
| 3347 | 14년 전 | 2311 | ||
| 3346 | 14년 전 | 1430 | ||
| 3345 | 14년 전 | 1354 | ||
| 3344 | 14년 전 | 885 | ||
| 3343 |
visualp
|
14년 전 | 1751 | |
| 3342 |
abetterday
|
14년 전 | 2722 | |
| 3341 |
|
14년 전 | 1223 | |
| 3340 |
|
14년 전 | 608 | |
| 3339 | 14년 전 | 2176 | ||
| 3338 |
|
14년 전 | 1938 | |
| 3337 | 14년 전 | 897 | ||
| 3336 | 14년 전 | 1473 | ||
| 3335 | 14년 전 | 1653 | ||
| 3334 | 14년 전 | 1505 | ||
| 3333 | 14년 전 | 878 | ||
| 3332 |
sooram
|
14년 전 | 837 | |
| 3331 | 14년 전 | 1138 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기