close

Trust Me!! Trust You!!


  • Blog
  • Local Log
  • Tag Cloud
  • Key Log
  • Guestbook
  • RSS Feed
  • Write a Post
  • Admin

혹시 블로그 스킨이 깨져 보이시나요? 최신버전의 Internet Explorer(Windows용), Opera, Firefox를 사용해보세요.

c# byte to gb,mb,kb,bytes

App 프로그래밍
2016/05/11 00:53
 
public string FormatBytes(long bytes)
{
  const int scale = 1024;
  string[] orders = new string[] { "GB", "MB", "KB", "Bytes" };
  long max = (long)Math.Pow(scale, orders.Length - 1);
 
  foreach (string order in orders)
  {
    if ( bytes > max )
      return string.Format("{0:##.##} {1}", decimal.Divide( bytes, max ), order);
 
    max /= scale;
  }
  return "0 Bytes";
}

개선전 코드
public string FormatBytes(int Bytes)
{
  string filesize;
  if (Bytes >= 1073741824)
  {
    decimal size = decimal.Divide(Bytes, 1073741824);
    filesize = string.Format("{0:##.##} GB", size);
  }
  else if (Bytes >= 1048576)
  {
    decimal size = decimal.Divide(Bytes, 1048576);
    filesize = string.Format("{0:##.##} MB", size);
  }
  else if (Bytes >= 1024)
  {
    decimal size = decimal.Divide(Bytes, 1024);
    filesize = string.Format("{0:##.##} KB", size);
  }
  else if (Bytes > 0 & Bytes < 1024)
  {
    decimal size = Bytes;
    filesize = string.Format("{0:##.##} Bytes", size);
  }
  else
  {
    filesize = "0 Bytes";
  }
  return filesize;
}
이올린에 북마크하기
No received trackback. / No comment.

Trackback Address :: http://viper150.cafe24.com/trackback/278

You can also say.

Prev 1 ... 22 23 24 25 26 27 28 29 30 ... 298 Next
블로그 이미지
이것저것 불펌금지도 퍼다가 담습니다. 외부에 비공개된 페이지 입니다. By. 어른왕자

카테고리

  • 전체 (298)
    • 사는 이야기 (115)
    • 웹 프로그래밍 (102)
    • App 프로그래밍 (22)
    • IT 뉴스&기타 (22)
    • 박한별 (4)
    • 역사&기타지식 (9)

태그목록

  • 몰카
  • k9
  • 여자
  • 방화벽예외
  • 아이유
  • Pop
  • api doc
  • context.xml
  • 얻은것
  • 톰켓
  • iops
  • NWS
  • 살수대첩
  • 보배드림
  • XSS
  • 환상의 커플
  • benchmark
  • 우리
  • 광고제거
  • 그래픽카드
  • html5
  • 욕심
  • 박근혜
  • 보안
  • 집안일
  • 1.6
  • 울트라에디터
  • 이클립스 루트
  • 건강보험
  • tomcat

최근에 올라온 글

  • 보험사의 조정신청 대응방법.
  • 어느 천재의 앞선 시선.
  • [병맛더빙] 누구게..... (1)
  • 韓경제 `회색 코뿔소` 상황...
  • SVN Connector 설치 URL.
  • 군대를 가지 않는 서울대생.
  • “운은 하늘의 귀여움 받는...
  • 목장에서 알바하다가 캐스...
  • [펌]믿고 거르는 관상.
  • 하루에 1세트씩 하면 좋다...

최근에 달린 댓글

  • 저도 칭구덕에 이젠 큰 부자가... 가현 04/12
  • 배우 김정현은 길지 않은 연기... 김정현 04/10
  • 정세균 국무총리는 4일 신종... 정세영 04/07
  • <p> '학폭을 인정한 적 없는'... 이가흔 04/05
  • 장동민은 "물론 전문가분들도... 장동민 04/02

최근에 받은 트랙백

  • Solace Salts Bold Tobacco. Solace Salts Bold Tobacco 03/29
  • read this post from Bookie 7. read this post from Bookie 7 02/28
  • công ty may đồng phục. công ty may đồng phục 01/08
  • Israelnightclub`s recent blo... Israelnightclub`s recent blo.. 01/06
  • Suggested Browsing. Suggested Browsing 01/06

글 보관함

  • 2019/03 (1)
  • 2018/12 (1)
  • 2018/09 (1)
  • 2018/08 (1)
  • 2018/02 (1)

달력

«   2021/04   »
일 월 화 수 목 금 토
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  

링크

  • Total : 265419
  • Today : 35
  • Yesterday : 55
Tattertools
Eolin
rss

어른왕자's blog is powered byTattertools1.1.2.2 : Animato