✂️ Formats a number using fixed-point notation.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
.gitignore
.travis.yml
LICENSE
README.md
toFixed.go
toFixed_test.go

README.md

toFixed

Build Status PRs Welcome GitHub license

Formats a number using fixed-point notation.

Installing

Use go get to install and update:

go get -u github.com/sqrthree/toFixed

Usage

Package toFixed will export a function ToFixed that formats a number using fixed-point notation.

Examples

ToFixed(1.2345678, 2) // => 1.23 float64 
ToFixed(1.2345678, 5) // => 1.23457 float64

Go to ./examples to see details.

Note

Function ToFixed will return a float64 value, if you want to get a string value, you can use fmt.Sprintf().

package main

import (
	"fmt"
)

func main() {
	var f float64 = 18.923487203
  
	fmt.Println(fmt.Sprintf("%.5f", f))  // => 18.92349 string
}

Tests

go test -v

sqrtthree.com  ·  GitHub @sqrthree  ·  Twitter @sqrtthree