Skip to content
6.3.7. Decimals

6.3.7. Decimals

Functions for manipulating decimal values with proper rounding. This should be used for modeling math on money amounts.

You must convert your numbers into decimal types using the helpers, and then use the decimal functions on these decimal types. It makes heavy usage of the github.com/shopspring/decimal go package.





to-decimal

Coerce a decimal in string, number, or decimal format into a decimal type.





decimal-string

Convert a decimal type into a string.





decimal-float

Convert a decimal type into a float.





decimal+

Add var arg decimals. Arguments are coerced into a decimal type.





decimal-

Subtract var arg decimals. Arguments are coerced into a decimal type.





decimal*

Multiply var arg decimals. Arguments are coerced into a decimal type.





decimal/

Divide var arg decimals. Arguments are coerced into a decimal type.

(assert-string= "1" (decimal-string (decimal/ 4 2 2)))





decimal=

Check equality of two decimals. Arguments are coerced into a decimal type.





decimal<

Check less than of two decimals. Arguments are coerced into a decimal type.





decimal<=

Check less than or equal of two decimals. Arguments are coerced into a decimal type.





decimal>

Check greater than of two decimals. Arguments are coerced into a decimal type.





decimal>=

Check greater than or equal of two decimals. Arguments are coerced into a decimal type.





decimal-pow

Raise a decimal to a power. Arguments are coerced into a decimal type.





decimal-floor

Compute the floor of a decimal. Arguments are coerced into a decimal type.





decimal-ceil

Compute the ceiling of a decimal. Arguments are coerced into a decimal type.





decimal-abs

Compute the absolute value of a decimal. Arguments are coerced into a decimal type.





decimal-sign

Get the sign (-1, 0, 1) of a decimal. Arguments are coerced into a decimal type.





decimal-round

Round a decimal. Several rounding modes are supported (see shopspring repo for more details). Arguments are coerced into a decimal type.





We use cookies to give you the best experience of using this website. By continuing to use this site, you accept our use of cookies. Please read our Cookie Policy for more information.