Skip to content

Commit 93d47aa

Browse files
committed
0.2.0 Currency
1 parent 51ed67f commit 93d47aa

File tree

16 files changed

+264
-80
lines changed

16 files changed

+264
-80
lines changed

libraries/Currency/.github/workflows/arduino-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ jobs:
66
runs-on: ubuntu-latest
77
timeout-minutes: 5
88
steps:
9-
- uses: actions/checkout@v4
10-
- uses: arduino/arduino-lint-action@v1
9+
- uses: actions/checkout@v5
10+
- uses: arduino/arduino-lint-action@v2
1111
with:
1212
library-manager: update
1313
compliance: strict

libraries/Currency/.github/workflows/arduino_test_runner.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
timeout-minutes: 20
99

1010
steps:
11-
- uses: actions/checkout@v4
11+
- uses: actions/checkout@v5
1212
- uses: ruby/setup-ruby@v1
1313
with:
1414
ruby-version: 2.6

libraries/Currency/.github/workflows/jsoncheck.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ on:
55
paths:
66
- '**.json'
77
pull_request:
8+
paths:
9+
- '**.json'
810

911
jobs:
1012
test:
1113
runs-on: ubuntu-latest
1214
timeout-minutes: 5
1315
steps:
14-
- uses: actions/checkout@v4
16+
- uses: actions/checkout@v5
1517
- name: json-syntax-check
1618
uses: limitusus/json-syntax-check@v2
1719
with:

libraries/Currency/CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.2.0] - 2025-11-25
10+
- fix derived functions (symbols).
11+
- add "acronym"-wrappers e.g. USD(value) and USD64(value)
12+
- deprecated the float/double API
13+
- renamed CURRENCY_LIB_VERSION
14+
- update GitHub actions
15+
- minor edits
16+
17+
----
18+
919
## [0.1.9] - 2024-04-11
1020
- update GitHub actions
1121
- minor edits
@@ -32,7 +42,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3242
- minor edits.
3343

3444
## [0.1.2] - 2021-10-20
35-
- update build-CI + badges
45+
- update build-CI + badges
3646
- adde pound
3747
- rename roubles
3848
## [0.1.1] - 2021-05-27

libraries/Currency/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021-2024 Rob Tillaart
3+
Copyright (c) 2021-2025 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

libraries/Currency/README.md

Lines changed: 81 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,60 @@ Arduino library to help formatting integers for printing as currency.
1818

1919
**Experimental**
2020

21-
The currency library contains a number of functions that help to print
21+
The currency library contains a number of functions that help to print
2222
integers as currency.
2323

2424
The currency functions assume you do the currency math in integer units.
25-
For dollars and euro's this would be cents. For numbers with more decimals
26-
it is a smaller unit.
25+
For dollars and euro's this would be cents. For numbers with more decimals
26+
it is a smaller unit.
2727

2828
Using integers makes addition, subtraction and multiplication of currency exact.
2929

30-
The library has experimental wrappers for float/double values.
31-
Not tested extensively yet.
32-
33-
Choosing int32_t as 'base' also means that there is a limit in terms
34-
of minimum and maximum values. When large amounts are needed one can
30+
Choosing int32_t as 'base' also means that there is a limit in terms
31+
of minimum and maximum values. When large amounts are needed one can
3532
use the currency64() or one of its derived formatters as this is based
3633
upon int64_t numbers.
3734

35+
The 0.2.0 version added wrapper functions in the form of a TLA (Three Letter Acronym).
36+
The TLA's are international used acronyms for currency e.g. CNY(value) or GBP(value).
37+
3838
There is a relation with the printHelpers class - https://github.com/RobTillaart/printHelpers
3939
When this currency library has matured it might be merged with printHelpers.
4040

41+
As always feedback (or ideas for extensions) are welcome.
42+
43+
44+
### Breaking change 0.2.0 float/double
45+
46+
The library 0.1.x had experimental wrappers for float/double values.
47+
Testing showed the limits of **float** => seven significant digits explicitly.
48+
As that caused the converted string to be incorrect (thus useless) this part
49+
of the API is deprecated.
50+
51+
52+
### Symbols
53+
54+
Not all symbol codes work on all platforms, so you need to test for your platform.
55+
56+
| name | sign | code | Notes |
57+
|:-------------------|:------:|:-------------|:--------|
58+
| Euro || Alt + 0128 |
59+
| Pound | £ | Alt + 0163 |
60+
| Dollar | $ | Alt + 36 |
61+
| Yen | ¥ | Alt + 0165 |
62+
| Cent | ¢ | Alt + 0162 |
63+
| Generic Currency | ¤ | Alt + 0164 |
64+
| Peseta || Alt + 158 |
65+
| Frank / Florin | ƒ | Alt + 159 |
66+
67+
More see e.g. https://www.webnots.com/alt-code-shortcuts-for-currency-symbols/
68+
4169

42-
#### Related
70+
### Related
4371

4472
- https://github.com/RobTillaart/printHelpers
73+
- https://www.easymarkets.com/eu/learn-centre/discover-trading/currency-acronyms-and-abbreviations/
74+
4575

4676
## Interface
4777

@@ -51,13 +81,13 @@ When this currency library has matured it might be merged with printHelpers.
5181

5282
The following functions are implemented:
5383

54-
### Core function
84+
### Core functions
5585

56-
- **char \* currency(int32_t value, uint8_t decimals, char decimalSeparator, char thousandSeparator, char symbol);**
57-
- **char \* currency64(int64_t value, uint8_t decimals, char decimalSeparator, char thousandSeparator, char symbol);**
86+
- **char \* currency(int32_t value, uint8_t decimals, char decimalSeparator, char thousandSeparator, char symbol)**
87+
- **char \* currency64(int64_t value, uint8_t decimals, char decimalSeparator, char thousandSeparator, char symbol)**
5888

5989

60-
### int32 Wrapper functions
90+
### int32_t Wrapper functions
6191

6292
- **char \* bitcoin(int32_t value)**
6393
- **char \* dollar(int32_t value)**
@@ -68,7 +98,7 @@ The following functions are implemented:
6898
- **char \* yuan(int32_t value)**
6999

70100

71-
### int64 Wrapper functions
101+
### int64_t Wrapper functions
72102

73103
- **char \* bitcoin64(int64_t value)**
74104
- **char \* dollar64(int64_t value)**
@@ -79,11 +109,35 @@ The following functions are implemented:
79109
- **char \* yuan64(int64_t value)**
80110

81111

82-
### float Wrapper functions
112+
### int32_t TLA Wrapper functions
113+
114+
- **char \* BTC(int32_t value)**
115+
- **char \* USD(int32_t value)**
116+
- **char \* EUR(int32_t value)**
117+
- **char \* GBP(int32_t value)**
118+
- **char \* RUB(int32_t value)**
119+
- **char \* JPY(int32_t value)**
120+
- **char \* CNY(int32_t value)**
121+
122+
123+
### int64_t TLA Wrapper functions
124+
125+
- **char \* BTC64(int32_t value)**
126+
- **char \* USD64(int32_t value)**
127+
- **char \* EUR64(int32_t value)**
128+
- **char \* GBP64(int32_t value)**
129+
- **char \* RUB64(int32_t value)**
130+
- **char \* JPY64(int32_t value)**
131+
- **char \* CNY64(int32_t value)**
83132

84-
Experimental - not tested
133+
134+
### Deprecated float/double Wrapper functions
135+
136+
Deprecated, has serious limitations, therefore commented in the library.
85137

86138
All assumes 2 decimals except bitcoin which has 6.
139+
The accuracy of a float is just 7 digits.
140+
On some platforms (e.g. UNO R3) float == double so one gets errors.
87141

88142
- **char \* bitcoinf(double value)**
89143
- **char \* dollarf(double value)**
@@ -101,8 +155,9 @@ See examples.
101155

102156
## Performance
103157

104-
Performance is hard to optimize. Most time is spend in splitting
105-
individual digits (div / mod 10).
158+
Performance is hard to optimize.
159+
Most time is spend in splitting individual digits (div / mod 10).
160+
The **divmod10()** function from my fast_math library might be an option.
106161

107162

108163
## Future
@@ -113,19 +168,19 @@ individual digits (div / mod 10).
113168

114169
#### Should
115170

171+
- investigate a better double/float API
172+
- investigate impact **divmod10()** for int32 and int64.
173+
116174
#### Could
117175

118-
- More wrapper functions?
119-
- test double parameters.
120-
- should decimals be a parameter too?
121-
- add BTC, USD, EUR, GBP, RUB, JPY, CNY, etc. (3+1 chars)
122-
- https://www.easymarkets.com/eu/learn-centre/discover-trading/currency-acronyms-and-abbreviations/
176+
- add more TLA wrapper functions
177+
- consider .h library only as codebase is rather small?
123178

124179
#### Won't
125180

126-
- currency conversion?
127-
- intern all in ???
128-
181+
- currency conversion
182+
- ratios change daily (or faster)
183+
- intern in pecunia
129184

130185
## Support
131186

libraries/Currency/currency.cpp

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: currency.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.9
4+
// VERSION: 0.2.0
55
// PURPOSE: Currency library for Arduino
66
// URL: https://github.com/RobTillaart/Currency
77

@@ -59,7 +59,7 @@ char * currency64(int64_t value, int decimals, char decimalSeparator, char thous
5959

6060
while ((pos < 1) || (v > 0))
6161
{
62-
// separators
62+
// separators
6363
if ((pos == 0) && (decimals > 0) ) tmp[index++] = decimalSeparator;
6464
if ((pos > 0) && (pos % 3 == 0) ) tmp[index++] = thousandSeparator;
6565
pos++;
@@ -86,29 +86,50 @@ char * currency64(int64_t value, int decimals, char decimalSeparator, char thous
8686
//
8787
// DERIVED FUNCTIONS
8888
//
89-
char * bitcoin(int32_t value) { return currency(value, 6, '.', ',', 'B'); }
89+
char * bitcoin(int32_t value) { return currency(value, 6, '.', ',', 'B'); }
9090
char * dollar(int32_t value) { return currency(value, 2, '.', ',', '$'); }
9191
char * euro(int32_t value) { return currency(value, 2, ',', '.', 'E'); }
92-
char * pound(int32_t value) { return currency(value, 2, ',', '.', 'L'); }
93-
char * roubles(int32_t value) { return currency(value, 2, ',', '.', 'P'); }
92+
char * pound(int32_t value) { return currency(value, 2, ',', '.', 'P'); }
93+
char * roubles(int32_t value) { return currency(value, 2, ',', '.', 'R'); }
9494
char * yen(int32_t value) { return currency(value, 2, '.', ',', 'Y'); }
95-
char * yuan(int32_t value) { return currency(value, 2, '.', ',', 'R'); }
95+
char * yuan(int32_t value) { return currency(value, 2, '.', ',', 'Y'); }
9696

97-
char * bitcoin64(int64_t value) { return currency64(value, 6, '.', ',', 'B'); }
97+
char * bitcoin64(int64_t value) { return currency64(value, 6, '.', ',', 'B'); }
9898
char * dollar64(int64_t value) { return currency64(value, 2, '.', ',', '$'); }
9999
char * euro64(int64_t value) { return currency64(value, 2, ',', '.', 'E'); }
100-
char * pound64(int64_t value) { return currency64(value, 2, ',', '.', 'L'); }
101-
char * roubles64(int64_t value) { return currency64(value, 2, ',', '.', 'P'); }
100+
char * pound64(int64_t value) { return currency64(value, 2, ',', '.', 'P'); }
101+
char * roubles64(int64_t value) { return currency64(value, 2, ',', '.', 'R'); }
102102
char * yen64(int64_t value) { return currency64(value, 2, '.', ',', 'Y'); }
103-
char * yuan64(int64_t value) { return currency64(value, 2, '.', ',', 'R'); }
104-
105-
char * bitcoinf(double value) { return currency64(round(value * 1000000), 6, '.', ',', 'B'); }
106-
char * dollarf(double value) { return currency64(round(value * 100), 2, '.', ',', '$'); }
107-
char * eurof(double value) { return currency64(round(value * 100), 2, ',', '.', 'E'); }
108-
char * poundf(double value) { return currency64(round(value * 100), 2, ',', '.', 'L'); }
109-
char * roublesf(double value) { return currency64(round(value * 100), 2, ',', '.', 'P'); }
110-
char * yenf(double value) { return currency64(round(value * 100), 2, '.', ',', 'Y'); }
111-
char * yuanf(double value) { return currency64(round(value * 100), 2, '.', ',', 'R'); }
103+
char * yuan64(int64_t value) { return currency64(value, 2, '.', ',', 'Y'); }
104+
105+
// deprecated
106+
// char * bitcoinf(double value) { return currency64(round(value * 1000000LL), 6, '.', ',', 'B'); }
107+
// char * dollarf(double value) { return currency64(round(value * 100LL), 2, '.', ',', '$'); }
108+
// char * eurof(double value) { return currency64(round(value * 100LL), 2, ',', '.', 'E'); }
109+
// char * poundf(double value) { return currency64(round(value * 100LL), 2, ',', '.', 'P'); }
110+
// char * roublesf(double value) { return currency64(round(value * 100LL), 2, ',', '.', 'R'); }
111+
// char * yenf(double value) { return currency64(round(value * 100LL), 2, '.', ',', 'Y'); }
112+
// char * yuanf(double value) { return currency64(round(value * 100LL), 2, '.', ',', 'Y'); }
113+
114+
115+
//
116+
// TLA - Three Letter Acronyms
117+
//
118+
char * BTC(int32_t value) { return currency(value, 6, '.', ',', 'B'); }
119+
char * USD(int32_t value) { return currency(value, 2, '.', ',', '$'); }
120+
char * EUR(int32_t value) { return currency(value, 2, ',', '.', 'E'); }
121+
char * GBP(int32_t value) { return currency(value, 2, ',', '.', 'P'); }
122+
char * RUB(int32_t value) { return currency(value, 2, ',', '.', 'R'); }
123+
char * JPY(int32_t value) { return currency(value, 2, '.', ',', 'Y'); }
124+
char * CNY(int32_t value) { return currency(value, 2, '.', ',', 'Y'); }
125+
126+
char * BTC64(int64_t value) { return currency64(value, 6, '.', ',', 'B'); }
127+
char * USD64(int64_t value) { return currency64(value, 2, '.', ',', '$'); }
128+
char * EUR64(int64_t value) { return currency64(value, 2, ',', '.', 'E'); }
129+
char * GBP64(int64_t value) { return currency64(value, 2, ',', '.', 'P'); }
130+
char * RUB64(int64_t value) { return currency64(value, 2, ',', '.', 'R'); }
131+
char * JPY64(int64_t value) { return currency64(value, 2, '.', ',', 'Y'); }
132+
char * CNY64(int64_t value) { return currency64(value, 2, '.', ',', 'Y'); }
112133

113134

114135
// -- END OF FILE --

0 commit comments

Comments
 (0)