pmiddend/elm-number-spinner/1.0.0

NumberSpinner.DigitalNumber

A "digital number" (surely a bad term) is a number where you have read/write access to its individual "digits" (decimal and integral). This module provides this data type. A digital number has a min and a max value as well (which determines the integral digits of the number), but you have to specify the number of decimal digits, since it cannot be inferred from min/max.

Types

type alias DecimalType =
DecimalNumber

Type alias for the decimal type used

Represents a decimal number which has bounds on the decimal places and the value contained

Construct

Return the decimal characters for the number (as chars, so just for display)

make : Int -> DecimalType -> DecimalType -> DecimalType -> DigitalNumber

Create a digital number (information hiding here, since we don't expose the type constructor directly)

Mutate

Decrease the d'th decimal digit of the number (taking care of under/overflow)

Decrease the d'th integer digit of the number (taking care of under/overflow)

Flip the sign (yeah, increase/decrease is weirdly named)

Flip the sign (yeah, increase/decrease is weirdly named)

Increase the d'th integer digit of the number (taking care of under/overflow)

Increase the d'th decimal digit of the number (taking care of under/overflow)

modifyValue : DigitalNumber -> (DecimalType -> DecimalType) -> DigitalNumber

Helper function to modify the value of a digital number, taking care of not over/underflowing it

Replace the whichDigit's integer digit with "newDigit" (so converting "123.45" to "123.95" or something)

Replace the whichDigit's integer digit with "newDigit" (so converting "123" to "193" or something)

Deconstruct

getValue : DigitalNumber -> DecimalType

Retrieve just the value of the digital number

Check if the number has decimal places at all. If not, we can omit the ".xxx" and make the input field more narrow.

Check if the number has a sign (used to determine if we display a plus/minus in front of it and making that changeable)

Return the integral characters for the number (as chars, so just for display)

Check if the number is currently negative

Return the number of decimal digits of the number (which is fixed on construction of the digital number)

Return the number of integral digits of the number (to display the correct number of digits in the UI)

Convert the decimal number to the approximate floating point value