Public Member Functions | List of all members
LargeFixedNumber Class Reference

#include <EditableLargeNumberMenuItem.h>

Public Member Functions

 LargeFixedNumber ()
void clear ()
int decimalPointIndex () const
void setPrecision (uint8_t dp, uint8_t maxDigits=12)
void setValue (uint32_t whole, uint32_t fraction, bool negative)
void setFromFloat (float value)
uint32_t fromBcdPacked (int start, int end)
void convertToBcdPacked (uint32_t value, int start, int end)
int getDigit (int digit)
void setDigit (int digit, int val)
float getAsFloat ()
bool isNegative () const
void setNegative (bool neg)
uint32_t getWhole ()
uint32_t getFraction ()
uint8_t * getNumberBuffer ()

Detailed Description

A structure for very large numbers that can be edited using the multipart editor. They are represented as binary coded decimal to 12 dp with between 0 and 9 fraction decimal places if needed. The whole can be either negative or positive between 1 and 9 decimal places. Both fraction and whole can be extracted as either a floating point, a per digit value, or as integers containing whole, fraction and negative flag.

Constructor & Destructor Documentation

◆ LargeFixedNumber()

LargeFixedNumber::LargeFixedNumber ( )

Create a default instance with decimal places set to 4 and total size 12.

Member Function Documentation

◆ clear()

void LargeFixedNumber::clear ( )

Clears the whole structure before setting to a new value

◆ decimalPointIndex()

int LargeFixedNumber::decimalPointIndex ( ) const
the number of decimal places this represents.

◆ setPrecision()

void LargeFixedNumber::setPrecision ( uint8_t  dp,
uint8_t  maxDigits = 12 

Set the number of decimal places and optionally the total size then zero out any currently held value. When setting this value you should ensure that: fractionDp is not larger than 9, the difference between fractionDp and maxDigits is not greater than 9.

dpthe new number of decimal places
maxDigitsthe total number of digits needed.

◆ setValue()

void LargeFixedNumber::setValue ( uint32_t  whole,
uint32_t  fraction,
bool  negative 

Sets the value of this instance without changing the decimal places.

wholethe whole part of the value
fractionthe fractional part of the value
negativeif the value to hold is negative.

◆ setFromFloat()

void LargeFixedNumber::setFromFloat ( float  value)

Takes a floating point value and converts it into the internal representation. This will represent the float within the bounds of the current total digits and decimal precision.

valuethe float value to convert

◆ fromBcdPacked()

uint32_t LargeFixedNumber::fromBcdPacked ( int  start,
int  end 

Converts from the BCD packed structure into an integer

startthe index to start in the packed data
endwill stop at one before this point
the integer value

◆ convertToBcdPacked()

void LargeFixedNumber::convertToBcdPacked ( uint32_t  value,
int  start,
int  end 

Converts from an integer into BCD packed.

valuethe value to be encoded
startthe index to start in the packed data
endwill stop at one before this point

◆ getDigit()

int LargeFixedNumber::getDigit ( int  digit)

get a particular digit from the bit packed structure.

digitthe number of the digit zero based.
the number at this location

◆ setDigit()

void LargeFixedNumber::setDigit ( int  digit,
int  val 

set a particular digit in the packed structure to a value

digitthe number of the digit zero based
valuethe new value for that digit

◆ getAsFloat()

float LargeFixedNumber::getAsFloat ( )

Gets the value converted to a float, note that floats cannot represent all values accurately and as such this will be the nearest float that represents the value. With numbers that get close to the 12 digit range it is highly possible that the float will be inaccurate.

the current represented value as a floating point number.

◆ isNegative()

bool LargeFixedNumber::isNegative ( ) const
true if negative otherwise false.

◆ setNegative()

void LargeFixedNumber::setNegative ( bool  neg)

Sets the negative flag, if true the number becomes a negative value.

negthe new negative flag value

◆ getWhole()

uint32_t LargeFixedNumber::getWhole ( )
the whole part of the value

◆ getFraction()

uint32_t LargeFixedNumber::getFraction ( )
the fractional part of the value

◆ getNumberBuffer()

uint8_t* LargeFixedNumber::getNumberBuffer ( )

Gets the underlying buffer to enable storage / loading from EEPROM

the underlying bcd buffer

The documentation for this class was generated from the following files: