:decimal_conv (FakeDecimal v0.1.2)

Copy Markdown View Source

The second module of the old erlang_decimal library: conversion between {coef, exp} decimals and binaries, charlists and floats.

Unlike :decimal, which is a thin shim over the Elixir Decimal library, this module is a direct port of the original Erlang source. The parser and the float printer decide which strings are valid and which digits a float produces, and those decisions have to match the original exactly — including the badarg raised on malformed input.

Summary

Types

binary_opts()

@type binary_opts() :: %{optional(:pretty) => boolean()}

Functions

from_binary(bin)

@spec from_binary(binary()) :: :decimal.decimal()

from_float(num)

@spec from_float(float()) :: :decimal.decimal()

from_list(list)

@spec from_list(charlist()) :: :decimal.decimal()

to_binary(arg, arg2)

@spec to_binary(:decimal.decimal(), binary_opts()) :: binary()