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);
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 4830 |
임페리얼웹
|
13년 전 | 1370 | |
| 4829 |
임페리얼웹
|
13년 전 | 722 | |
| 4828 | 13년 전 | 3484 | ||
| 4827 |
|
13년 전 | 1241 | |
| 4826 | 13년 전 | 2749 | ||
| 4825 | 13년 전 | 1085 | ||
| 4824 |
gnuskin쩜net
|
13년 전 | 771 | |
| 4823 | 13년 전 | 819 | ||
| 4822 |
visualp
|
13년 전 | 685 | |
| 4821 |
다케미카코
|
13년 전 | 1262 | |
| 4820 | 13년 전 | 1347 | ||
| 4819 | 13년 전 | 2666 | ||
| 4818 |
크라이스트
|
13년 전 | 4239 | |
| 4817 |
임페리얼웹
|
13년 전 | 714 | |
| 4816 | 13년 전 | 3264 | ||
| 4815 |
하모니칼수
|
13년 전 | 653 | |
| 4814 | 13년 전 | 1112 | ||
| 4813 | 13년 전 | 710 | ||
| 4812 |
임페리얼웹
|
13년 전 | 1088 | |
| 4811 |
임페리얼웹
|
13년 전 | 1835 | |
| 4810 | 13년 전 | 1151 | ||
| 4809 | 13년 전 | 631 | ||
| 4808 | 13년 전 | 1285 | ||
| 4807 |
너는나의봄이다
|
13년 전 | 896 | |
| 4806 | 13년 전 | 1294 | ||
| 4805 | 13년 전 | 1775 | ||
| 4804 | 13년 전 | 1074 | ||
| 4803 |
한번잘해보자
|
13년 전 | 719 | |
| 4802 | 13년 전 | 1906 | ||
| 4801 |
꼬꼬아부지
|
13년 전 | 1186 | |
| 4800 | 13년 전 | 777 | ||
| 4799 |
|
13년 전 | 725 | |
| 4798 | 13년 전 | 1076 | ||
| 4797 |
한번잘해보자
|
13년 전 | 616 | |
| 4796 | 13년 전 | 1723 | ||
| 4795 | 13년 전 | 1003 | ||
| 4794 |
|
13년 전 | 1018 | |
| 4793 |
|
13년 전 | 658 | |
| 4792 | 13년 전 | 1292 | ||
| 4791 | 13년 전 | 2100 | ||
| 4790 |
|
13년 전 | 622 | |
| 4789 |
한번잘해보자
|
13년 전 | 515 | |
| 4788 |
|
13년 전 | 694 | |
| 4787 | 13년 전 | 3286 | ||
| 4786 |
한번잘해보자
|
13년 전 | 758 | |
| 4785 | 13년 전 | 1307 | ||
| 4784 | 13년 전 | 1078 | ||
| 4783 |
|
13년 전 | 725 | |
| 4782 | 13년 전 | 7735 | ||
| 4781 |
크라운엠버서더
|
13년 전 | 1107 | |
| 4780 | 13년 전 | 1755 | ||
| 4779 | 13년 전 | 758 | ||
| 4778 | 13년 전 | 1088 | ||
| 4777 | 13년 전 | 919 | ||
| 4776 | 13년 전 | 1887 | ||
| 4775 | 13년 전 | 3318 | ||
| 4774 | 13년 전 | 1534 | ||
| 4773 | 13년 전 | 3241 | ||
| 4772 | 13년 전 | 1418 | ||
| 4771 | 13년 전 | 3862 | ||
| 4770 | 13년 전 | 1425 | ||
| 4769 | 13년 전 | 911 | ||
| 4768 | 13년 전 | 1887 | ||
| 4767 | 13년 전 | 2663 | ||
| 4766 | 13년 전 | 1574 | ||
| 4765 | 13년 전 | 1381 | ||
| 4764 | 13년 전 | 3141 | ||
| 4763 | 13년 전 | 1164 | ||
| 4762 |
|
13년 전 | 724 | |
| 4761 | 13년 전 | 1611 | ||
| 4760 | 13년 전 | 852 | ||
| 4759 |
NTYPE
|
13년 전 | 5177 | |
| 4758 |
프로프리랜서
|
13년 전 | 828 | |
| 4757 |
프로프리랜서
|
13년 전 | 1215 | |
| 4756 | 13년 전 | 815 | ||
| 4755 |
원시인교주
|
13년 전 | 837 | |
| 4754 |
there007
|
13년 전 | 956 | |
| 4753 | 13년 전 | 1766 | ||
| 4752 |
세상의중심
|
13년 전 | 1577 | |
| 4751 | 13년 전 | 1301 | ||
| 4750 | 13년 전 | 1500 | ||
| 4749 |
또다른세상
|
13년 전 | 3655 | |
| 4748 | 13년 전 | 769 | ||
| 4747 |
cula100jak
|
13년 전 | 1658 | |
| 4746 | 13년 전 | 1480 | ||
| 4745 |
|
13년 전 | 618 | |
| 4744 |
designcity
|
13년 전 | 744 | |
| 4743 | 13년 전 | 621 | ||
| 4742 |
|
13년 전 | 8356 | |
| 4741 | 13년 전 | 849 | ||
| 4740 | 13년 전 | 1655 | ||
| 4739 | 13년 전 | 1324 | ||
| 4738 |
|
13년 전 | 752 | |
| 4737 |
Xerro
|
13년 전 | 492 | |
| 4736 | 13년 전 | 3723 | ||
| 4735 |
keith
|
13년 전 | 542 | |
| 4734 |
|
13년 전 | 698 | |
| 4733 | 13년 전 | 1753 | ||
| 4732 |
|
13년 전 | 1251 | |
| 4731 |
|
13년 전 | 1296 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기