money

package module
v0.0.0-...-5b1f211 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2017 License: MIT Imports: 3 Imported by: 2

README

money

Go package supporting simply money types

USD

At the time of this writing, money only supports USD. The following operations are supported:

func NewUSD() *USD  
func ToUSD(f float64) USD  
func (m USD) Float64() float64  
func (m USD) Multiply(f float64) USD  
func (m *USD) Scan(val interface{}) error  
func (m USD) String() string  

Documentation

Overview

Package money represents money in a stable, integer-based way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type USD

type USD int64

USD represents USD currecny

func NewUSD

func NewUSD() *USD

NewUSD returns a new zero-value instance of USD

func ToUSD

func ToUSD(f float64) USD

ToUSD converts a float64 to USD, rounding to two decimal places

func (USD) Float64

func (m USD) Float64() float64

Float64 converts USD to float64

func (USD) Multiply

func (m USD) Multiply(f float64) USD

Multiply returns the USD product of a USD value with a float64

func (*USD) Scan

func (m *USD) Scan(val interface{}) error

Scan attempts to scan a value into USD

func (USD) String

func (m USD) String() string

String returns a formatted USD value

func (USD) Value

func (m USD) Value() (driver.Value, error)

Value converts USD to a DB-friendly value. Although USD is stored in cents, the Value will be a two-decimal numeric type; e.g. $18.00 is stored under the hood by USD as 1800, but Value() would return 18.00 for the DB.

Jump to

Keyboard shortcuts

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