currency

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package currency contains utility functions for currencies.

Index

Examples

Constants

View Source
const PenniesInDollar float64 = 100

PenniesInDollar represents that there are 100 pennies in a dollar

Variables

This section is empty.

Functions

func DollarsToPennies

func DollarsToPennies(dollars float64, roundUp bool) int

DollarsToPennies converts a floating point value in dollars to pennies. If `roundUp` is true any fractional value that is less than 1 penny will be rounded up and added as an additional penny, eg 13.001 -> 1301. If the dollars amount is negative, and there is a fractional amount remaining and roundUp is true, the fractional amount will be rounded to a penny and added negatively to the output value, eg (-13.001 -> -1301). Otherwise, if roundUp is false, that value will be discarded.

Example
fmt.Println(DollarsToPennies(19.136, true))
Output:

1914

Types

This section is empty.

Jump to

Keyboard shortcuts

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