mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.8 Currency
This commit is contained in:
parent
fa0c291617
commit
d7b3c7cc42
@ -6,11 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.8] - 2023-10-19
|
||||
- update readme.md
|
||||
|
||||
|
||||
## [0.1.7] - 2022-10-30
|
||||
- add changelog.md
|
||||
- add rp2040 to build-CI
|
||||
|
||||
|
||||
## [0.1.6] - 2022-04-15
|
||||
- fix #5 split .h in .h and .cpp
|
||||
|
||||
|
@ -1,21 +1,23 @@
|
||||
|
||||
[![Arduino CI](https://github.com/RobTillaart/currency/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![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)
|
||||
[![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)
|
||||
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/currency.svg)](https://github.com/RobTillaart/currency/issues)
|
||||
|
||||
[![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)
|
||||
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/currency.svg)](https://registry.platformio.org/libraries/robtillaart/currency)
|
||||
|
||||
|
||||
# Currency
|
||||
|
||||
Arduino library to help formatting integers for printing as currency.
|
||||
|
||||
#### Warning: experimental
|
||||
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
**Experimental**
|
||||
|
||||
The currency library contains a number of functions that help to print
|
||||
integers as currency.
|
||||
|
||||
@ -37,10 +39,17 @@ There is a relation with the printHelpers class - https://github.com/RobTillaart
|
||||
When this currency library has matured it might be merged with printHelpers.
|
||||
|
||||
|
||||
#### Related
|
||||
|
||||
- https://github.com/RobTillaart/printHelpers
|
||||
|
||||
## Interface
|
||||
|
||||
The following functions are implemented:
|
||||
```cpp
|
||||
#include "currency.h"
|
||||
```
|
||||
|
||||
The following functions are implemented:
|
||||
|
||||
### Core function
|
||||
|
||||
@ -98,18 +107,31 @@ individual digits (div / mod 10).
|
||||
|
||||
## Future
|
||||
|
||||
#### must
|
||||
#### Must
|
||||
|
||||
- update documentation.
|
||||
|
||||
#### should
|
||||
#### Should
|
||||
|
||||
#### Could
|
||||
|
||||
#### could
|
||||
- More wrapper functions?
|
||||
- test double parameters.
|
||||
- should decimals be a parameter too?
|
||||
- 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/
|
||||
|
||||
#### won't
|
||||
#### Won't
|
||||
|
||||
- currency conversion?
|
||||
- intern all in ???
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
If you appreciate my libraries, you can support the development and maintenance.
|
||||
Improve the quality of the libraries by providing issues and Pull Requests, or
|
||||
donate through PayPal or GitHub sponsors.
|
||||
|
||||
Thank you,
|
||||
|
||||
|
@ -1,11 +1,9 @@
|
||||
//
|
||||
// FILE: currency.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.7
|
||||
// VERSION: 0.1.8
|
||||
// PURPOSE: Currency library for Arduino
|
||||
// URL: https://github.com/RobTillaart/Currency
|
||||
//
|
||||
// HISTORY: see changelog.md
|
||||
|
||||
|
||||
#include "currency.h"
|
||||
@ -20,11 +18,11 @@ char * currency(int32_t value, int decimals, char decimalSeparator, char thousan
|
||||
bool negative = v < 0;
|
||||
if (negative) v = -v;
|
||||
|
||||
int pos = -decimals; // decimal places
|
||||
int pos = -decimals; // decimal places
|
||||
|
||||
while ((pos < 1) || (v > 0))
|
||||
{
|
||||
// separators
|
||||
// separators
|
||||
if ((pos == 0) && (decimals > 0) ) tmp[index++] = decimalSeparator;
|
||||
if ((pos > 0) && (pos % 3 == 0) ) tmp[index++] = thousandSeparator;
|
||||
pos++;
|
||||
@ -37,7 +35,7 @@ char * currency(int32_t value, int decimals, char decimalSeparator, char thousan
|
||||
tmp[index++] = symbol;
|
||||
tmp[index] = '\0';
|
||||
|
||||
// reverse string
|
||||
// reverse string
|
||||
for (uint8_t i = 0, j = index - 1; i < index / 2; i++, j--)
|
||||
{
|
||||
char c = tmp[i];
|
||||
@ -57,7 +55,7 @@ char * currency64(int64_t value, int decimals, char decimalSeparator, char thous
|
||||
bool negative = v < 0;
|
||||
if (negative) v = -v;
|
||||
|
||||
int pos = -decimals; // decimal places
|
||||
int pos = -decimals; // decimal places
|
||||
|
||||
while ((pos < 1) || (v > 0))
|
||||
{
|
||||
@ -74,7 +72,7 @@ char * currency64(int64_t value, int decimals, char decimalSeparator, char thous
|
||||
tmp[index++] = symbol;
|
||||
tmp[index] = '\0';
|
||||
|
||||
// reverse string
|
||||
// reverse string
|
||||
for (uint8_t i = 0, j = index - 1; i < index / 2; i++, j--)
|
||||
{
|
||||
char c = tmp[i];
|
||||
@ -113,4 +111,4 @@ char * yenf(double value) { return currency64(round(value * 100), 2, '.',
|
||||
char * yuanf(double value) { return currency64(round(value * 100), 2, '.', ',', 'R'); }
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
@ -1,9 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// FILE: currency.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.7
|
||||
// VERSION: 0.1.8
|
||||
// PURPOSE: Currency library for Arduino
|
||||
// URL: https://github.com/RobTillaart/Currency
|
||||
|
||||
@ -11,7 +10,7 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#define CURRENCY_VERSION (F("0.1.7"))
|
||||
#define CURRENCY_VERSION (F("0.1.8"))
|
||||
|
||||
|
||||
// TODO
|
||||
@ -55,5 +54,5 @@ char * yenf(double value);
|
||||
char * yuanf(double value);
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -15,9 +15,9 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/currency"
|
||||
},
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.8",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
"headers": "currency.h"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=currency
|
||||
version=0.1.7
|
||||
version=0.1.8
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library to help formatting integers as currency e.g. $ 1.000.000,00.
|
||||
|
Loading…
Reference in New Issue
Block a user