function my_formatSize($size){$size = doubleval($size);$rank =0;$rankchar ='Bytes';while($size>1024){ $size = $size/1024; $rank++;}if($rank==1){ $rankchar="KB";}else if($rank==2){ $rankchar= "MB";}else if($rank==3){ $rankchar="GB";}$size =number_format($size, 2, '.', '');return "" .$size." ".$rankchar;}コードをコピー2. js実装コード function my_formatSize($size){ var size = parseFloat($size); var Rank =0; var Rankchar ='Bytes'; while(size>1024){ size = size/1024;rank++; } if(rank==1){rankchar="KB"; } else if(rank==2){rankchar="MB"; } else if(rank==3){rankchar="GB"; } return size.toFixed(2)+ " "+ Rankchar;}?> コードをコピー 注: code 小数点以下 2 桁を保持します。