shortscale

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2021 License: MIT Imports: 1 Imported by: 0

README

shortscale

CI
Go.dev github.com/jldec/shortscale-go

Go package to convert numbers into English words.

This was originally written as an exploration of JavaScript and Rust documented here.

The short scale, has different words for each power of 1000.

This library expresses numbers from zero to thousands, millions, billions, trillions, and quadrillions, up to 999_999_999_999_999_999.

Function
func Shortscale(n uint64) string
Example
import (
    "fmt"
    shortscale "github.com/jldec/shortscale-go"
)

// four hundred and twenty billion nine hundred and ninety nine thousand and fifteen
fmt.Println(shortscale.Shortscale(420_000_999_015))
Benchmarks
goos: darwin
goarch: amd64
pkg: github.com/jldec/shortscale-go
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
4053015	       291.8 ns/op	     120 B/op	       4 allocs/op

goos: linux
goarch: amd64
pkg: github.com/jldec/shortscale-go
2569018	       472 ns/op	     120 B/op	       4 allocs/op

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Shortscale

func Shortscale(n uint64) string

Shortscale converts numbers into English words. Supports positive integers from 0 to 999_999_999_999_999_999. Larger values return "(big number)".

Example
package main

import (
	"fmt"

	shortscale "github.com/jldec/shortscale-go"
)

func main() {
	fmt.Println(shortscale.Shortscale(420_000_999_015))
}
Output:

four hundred and twenty billion nine hundred and ninety nine thousand and fifteen

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL