您当前的位置: 首页 >  golang

彭世瑜

暂无认证

  • 4浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Golang:go-humanize将文件大小转换成Kb、Mb、Gb适合人类阅读的单位

彭世瑜 发布时间:2022-09-23 09:58:01 ,浏览量:4

Go Humans! (formatters for units to human friendly sizes)

译文:加油人类!(适合人类使用的单位的格式化程序)

文档

  • pkg.go https://pkg.go.dev/github.com/dustin/go-humanize
  • github https://github.com/dustin/go-humanize

安装

go get github.com/dustin/go-humanize

示例

package main

import (
    "fmt"

    "github.com/dustin/go-humanize"
)

func main() {

    fmt.Println(humanize.Bytes(8285))
    // 8.3 kB

    fmt.Println(humanize.Bytes(82854982))
    // 83 MB
}

参考 「Go工具箱」将文件大小转换成Kb、Mb、Gb就用这个库:go-humanize

关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.0560s