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);
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 930 | 19년 전 | 3545 | ||
| 929 |
|
19년 전 | 2707 | |
| 928 |
|
19년 전 | 3455 | |
| 927 |
|
19년 전 | 3444 | |
| 926 |
|
19년 전 | 3149 | |
| 925 | 19년 전 | 5434 | ||
| 924 |
|
19년 전 | 2170 | |
| 923 |
|
19년 전 | 2224 | |
| 922 |
|
19년 전 | 2316 | |
| 921 |
|
19년 전 | 3412 | |
| 920 | 19년 전 | 3709 | ||
| 919 |
|
19년 전 | 3749 | |
| 918 |
|
19년 전 | 2366 | |
| 917 |
|
19년 전 | 2400 | |
| 916 |
|
19년 전 | 2707 | |
| 915 | 19년 전 | 3051 | ||
| 914 | 19년 전 | 2463 | ||
| 913 | 19년 전 | 2627 | ||
| 912 | 19년 전 | 2462 | ||
| 911 | 19년 전 | 2216 | ||
| 910 | 19년 전 | 3249 | ||
| 909 | 19년 전 | 3311 | ||
| 908 | 19년 전 | 3042 | ||
| 907 |
|
19년 전 | 4876 | |
| 906 |
|
19년 전 | 2719 | |
| 905 |
|
19년 전 | 3319 | |
| 904 |
|
19년 전 | 3154 | |
| 903 |
|
19년 전 | 1997 | |
| 902 |
|
19년 전 | 3147 | |
| 901 |
|
19년 전 | 1881 | |
| 900 |
|
19년 전 | 2340 | |
| 899 |
|
19년 전 | 2404 | |
| 898 |
|
19년 전 | 3986 | |
| 897 |
|
19년 전 | 3188 | |
| 896 |
|
19년 전 | 3106 | |
| 895 |
|
19년 전 | 2542 | |
| 894 |
|
19년 전 | 2019 | |
| 893 |
|
19년 전 | 1651 | |
| 892 |
|
19년 전 | 2418 | |
| 891 |
|
19년 전 | 2330 | |
| 890 |
|
19년 전 | 1816 | |
| 889 |
|
19년 전 | 1813 | |
| 888 |
|
19년 전 | 2613 | |
| 887 |
|
19년 전 | 2584 | |
| 886 |
|
19년 전 | 1876 | |
| 885 |
|
19년 전 | 2115 | |
| 884 |
|
19년 전 | 3307 | |
| 883 |
|
19년 전 | 1955 | |
| 882 |
|
19년 전 | 2503 | |
| 881 |
|
19년 전 | 2582 | |
| 880 |
|
19년 전 | 2664 | |
| 879 |
|
19년 전 | 2939 | |
| 878 |
|
19년 전 | 2561 | |
| 877 |
|
19년 전 | 2984 | |
| 876 |
|
19년 전 | 2762 | |
| 875 |
|
19년 전 | 3524 | |
| 874 | 19년 전 | 1873 | ||
| 873 | 19년 전 | 2736 | ||
| 872 |
|
19년 전 | 2376 | |
| 871 |
|
19년 전 | 2020 | |
| 870 |
|
19년 전 | 2427 | |
| 869 |
|
19년 전 | 1873 | |
| 868 |
|
19년 전 | 5441 | |
| 867 |
|
19년 전 | 2266 | |
| 866 |
|
19년 전 | 4265 | |
| 865 |
|
19년 전 | 2304 | |
| 864 | 19년 전 | 1854 | ||
| 863 | 19년 전 | 2608 | ||
| 862 | 19년 전 | 2335 | ||
| 861 | 19년 전 | 2536 | ||
| 860 | 19년 전 | 2165 | ||
| 859 | 19년 전 | 3929 | ||
| 858 | 19년 전 | 3422 | ||
| 857 | 19년 전 | 2199 | ||
| 856 |
Power
|
19년 전 | 2109 | |
| 855 | 19년 전 | 1972 | ||
| 854 | 19년 전 | 2006 | ||
| 853 |
pearly
|
19년 전 | 4391 | |
| 852 |
pearly
|
19년 전 | 3358 | |
| 851 | 19년 전 | 2779 | ||
| 850 |
pearly
|
19년 전 | 3355 | |
| 849 |
pearly
|
19년 전 | 3015 | |
| 848 |
pearly
|
19년 전 | 2845 | |
| 847 | 19년 전 | 2369 | ||
| 846 |
|
19년 전 | 2177 | |
| 845 |
pearly
|
19년 전 | 2496 | |
| 844 | 19년 전 | 3105 | ||
| 843 | 19년 전 | 2134 | ||
| 842 |
pearly
|
19년 전 | 3125 | |
| 841 |
pearly
|
19년 전 | 3249 | |
| 840 | 19년 전 | 2930 | ||
| 839 |
|
19년 전 | 1945 | |
| 838 |
|
19년 전 | 1708 | |
| 837 |
|
19년 전 | 2330 | |
| 836 |
|
19년 전 | 2273 | |
| 835 |
|
19년 전 | 1649 | |
| 834 |
|
19년 전 | 1667 | |
| 833 |
|
19년 전 | 1574 | |
| 832 |
|
19년 전 | 2068 | |
| 831 |
|
19년 전 | 1617 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기