Created
August 27, 2016 01:13
-
-
Save palemoky/39127ff4248fbc5271a661a671660a99 to your computer and use it in GitHub Desktop.
实现文件单位的快速转换,这是我的第一个函数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm | |
* User: Xinyu | |
* Date: 16/8/25 | |
* Time: 下午10:09 | |
*/ | |
function unitConvert($scale){ | |
if($scale >= (1<<30)){ | |
$scale /= (1<<30); | |
$scale = round($scale,2); | |
echo $scale,'GB'; | |
}else if($scale >= (1<<20)){ | |
$scale /= (1<<20); | |
$scale = round($scale,2); | |
echo $scale,'MB'; | |
}else if($scale >= (1<<10)){ | |
$scale /= (1<<10); | |
$scale = round($scale,2); | |
echo $scale,'KB'; | |
}else{ | |
echo $scale,'B'; | |
} | |
} | |
?> |
Author
palemoky
commented
Jul 31, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment