Skip to content

Instantly share code, notes, and snippets.

@ykyuen
Created January 22, 2018 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ykyuen/4f10c57ea235e5cbed938dce9e022e76 to your computer and use it in GitHub Desktop.
Save ykyuen/4f10c57ea235e5cbed938dce9e022e76 to your computer and use it in GitHub Desktop.
manage-go-dependencies-using-dep-04
package main
import humanize "github.com/dustin/go-humanize"
import accounting "github.com/leekchan/accounting"
import "math/big"
import "fmt"
func main() {
fmt.Println("hello world")
fmt.Printf("That file is %s.\n", humanize.Bytes(82854982)) // That file is 83 MB.
fmt.Printf("You're my %s best friend.\n", humanize.Ordinal(193)) // You are my 193rd best friend.
fmt.Printf("You owe $%s.\n", humanize.Comma(6582491)) // You owe $6,582,491.
ac := accounting.Accounting{Symbol: "$", Precision: 2}
fmt.Println(ac.FormatMoney(123456789.213123)) // "$123,456,789.21"
fmt.Println(ac.FormatMoney(12345678)) // "$12,345,678.00"
fmt.Println(ac.FormatMoney(big.NewRat(77777777, 3))) // "$25,925,925.67"
fmt.Println(ac.FormatMoney(big.NewRat(-77777777, 3))) // "-$25,925,925.67"
fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(123456789.213123))) // "$123,456,789.21"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment