2021-03-01 04:11:54 -05:00
|
|
|
|
|
|
|
[![Arduino CI](https://github.com/RobTillaart/currency/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
2021-10-20 05:24:55 -04:00
|
|
|
[![Arduino-lint](https://github.com/RobTillaart/Currency/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/Currency/actions/workflows/arduino-lint.yml)
|
|
|
|
[![JSON check](https://github.com/RobTillaart/Currency/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/Currency/actions/workflows/jsoncheck.yml)
|
2021-03-01 04:11:54 -05:00
|
|
|
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/currency/blob/master/LICENSE)
|
|
|
|
[![GitHub release](https://img.shields.io/github/release/RobTillaart/currency.svg?maxAge=3600)](https://github.com/RobTillaart/currency/releases)
|
|
|
|
|
|
|
|
|
|
|
|
# Currency
|
|
|
|
|
2021-12-15 05:20:58 -05:00
|
|
|
Arduino library to help formatting integers for printing as currency.
|
2021-03-01 04:11:54 -05:00
|
|
|
|
2022-10-30 15:44:02 -04:00
|
|
|
#### Warning: experimental
|
2021-03-01 04:11:54 -05:00
|
|
|
|
|
|
|
|
2021-12-14 16:08:54 -05:00
|
|
|
|
2021-03-01 04:11:54 -05:00
|
|
|
## Description
|
|
|
|
|
|
|
|
The currency library contains a number of functions that help to print
|
|
|
|
integers as currency.
|
|
|
|
|
|
|
|
The currency functions assume you do the currency math in integer units.
|
|
|
|
For dollars and euro's this would be cents. For numbers with more decimals
|
|
|
|
it is a smaller unit.
|
|
|
|
|
2021-12-15 05:20:58 -05:00
|
|
|
Using integers makes addition, subtraction and multiplication of currency exact.
|
2021-10-20 05:24:55 -04:00
|
|
|
|
|
|
|
The library has experimental wrappers for float/double values.
|
|
|
|
Not tested extensively yet.
|
2021-03-01 04:11:54 -05:00
|
|
|
|
|
|
|
Choosing int32_t as 'base' also means that there is a limit in terms
|
|
|
|
of minimum and maximum values. When large amounts are needed one can
|
|
|
|
use the currency64() or one of its derived formatters as this is based
|
|
|
|
upon int64_t numbers.
|
|
|
|
|
2021-12-14 16:08:54 -05:00
|
|
|
There is a relation with the printHelpers class - https://github.com/RobTillaart/printHelpers
|
|
|
|
When this currency library has matured it might be merged with printHelpers.
|
2021-03-01 04:11:54 -05:00
|
|
|
|
|
|
|
|
|
|
|
## Interface
|
|
|
|
|
|
|
|
The following functions are implemented:
|
|
|
|
|
|
|
|
|
|
|
|
### Core function
|
|
|
|
|
2021-12-14 16:08:54 -05:00
|
|
|
- **char \* currency(int32_t value, uint8_t decimals, char decimalSeparator, char thousandSeparator, char symbol);**
|
|
|
|
- **char \* currency64(int64_t value, uint8_t decimals, char decimalSeparator, char thousandSeparator, char symbol);**
|
2021-03-01 04:11:54 -05:00
|
|
|
|
|
|
|
|
|
|
|
### int32 Wrapper functions
|
|
|
|
|
|
|
|
- **char \* bitcoin(int32_t value)**
|
|
|
|
- **char \* dollar(int32_t value)**
|
|
|
|
- **char \* euro(int32_t value)**
|
2021-10-20 05:24:55 -04:00
|
|
|
- **char \* pound(int32_t value)**
|
|
|
|
- **char \* roubles(int32_t value)**
|
2021-03-01 04:11:54 -05:00
|
|
|
- **char \* yen(int32_t value)**
|
|
|
|
- **char \* yuan(int32_t value)**
|
|
|
|
|
|
|
|
|
|
|
|
### int64 Wrapper functions
|
|
|
|
|
|
|
|
- **char \* bitcoin64(int64_t value)**
|
|
|
|
- **char \* dollar64(int64_t value)**
|
|
|
|
- **char \* euro64(int64_t value)**
|
2021-10-20 05:24:55 -04:00
|
|
|
- **char \* pound64(int64_t value)**
|
|
|
|
- **char \* roubles64(int64_t value)**
|
2021-03-01 04:11:54 -05:00
|
|
|
- **char \* yen64(int64_t value)**
|
|
|
|
- **char \* yuan64(int64_t value)**
|
|
|
|
|
|
|
|
|
|
|
|
### float Wrapper functions
|
|
|
|
|
2021-12-15 05:20:58 -05:00
|
|
|
Experimental - not tested
|
|
|
|
|
|
|
|
All assumes 2 decimals except bitcoin which has 6.
|
2021-03-01 04:11:54 -05:00
|
|
|
|
|
|
|
- **char \* bitcoinf(double value)**
|
|
|
|
- **char \* dollarf(double value)**
|
|
|
|
- **char \* eurof(double value)**
|
2021-10-20 05:24:55 -04:00
|
|
|
- **char \* poundf(double value)**
|
|
|
|
- **char \* roublesf(double value)**
|
2021-03-01 04:11:54 -05:00
|
|
|
- **char \* yenf(double value)**
|
|
|
|
- **char \* yuanf(double value)**
|
|
|
|
|
|
|
|
|
2021-12-14 16:08:54 -05:00
|
|
|
## Operation
|
|
|
|
|
2021-12-15 05:20:58 -05:00
|
|
|
See examples.
|
|
|
|
|
|
|
|
|
|
|
|
## Performance
|
|
|
|
|
|
|
|
Performance is hard to optimize. Most time is spend in splitting
|
|
|
|
individual digits (div / mod 10).
|
2021-12-14 16:08:54 -05:00
|
|
|
|
|
|
|
|
2021-03-01 04:11:54 -05:00
|
|
|
## Future
|
|
|
|
|
2022-10-30 15:44:02 -04:00
|
|
|
#### must
|
2021-12-14 16:08:54 -05:00
|
|
|
- update documentation.
|
2022-10-30 15:44:02 -04:00
|
|
|
|
|
|
|
#### should
|
|
|
|
|
|
|
|
#### could
|
2021-03-01 04:11:54 -05:00
|
|
|
- More wrapper functions?
|
|
|
|
- test double parameters.
|
2021-12-15 05:20:58 -05:00
|
|
|
- should decimals be a parameter too?
|
2021-10-20 05:24:55 -04:00
|
|
|
- add BTC, USD, EUR, GBP, RUB, JPY, CNY, etc. (3+1 chars)
|
|
|
|
- https://www.easymarkets.com/eu/learn-centre/discover-trading/currency-acronyms-and-abbreviations/
|
2021-03-01 04:11:54 -05:00
|
|
|
|
2022-10-30 15:44:02 -04:00
|
|
|
#### won't
|
2021-12-15 05:20:58 -05:00
|
|
|
- currency conversion?
|
|
|
|
- intern all in ???
|