CurrencyX Support in div. Languages (continued)

Started by Theo Gottwald, June 10, 2026, 07:02:30 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Theo Gottwald

I have never used that in mylife so CurrencyX is not yet implemented, i did not even know it existed.
But this can be implemented after all current features are bug free.

Implementing just a compatibility wrapper could be done using a Macro replaces CurrencyX with Currency.
As our Macros are not limited to inside functions this should work.

If you for whatever reason really need the extended precision it must be implemented from scratch.
Here with these C-based Compilers implementing Datattypes that are not available in C is a bit more todo, especially as the runtime can not just coded from C, but i think its doable (like EXT also).

If you really plan to use the compiler and this feature is "what i need" tell me and we can do that.
It might anyway be in the next Update for PBXB64 (that is the other compiler).
PBXA64 is just under the knife.


What CURRENCYX adds:
Based on PB documentation, CURRENCYX is a 128-bit (16-byte) fixed-point decimal with:

96-bit signed integer mantissa (range ~±7.9 × 10^28)
24-bit unsigned scale exponent (variable scale, not just 4 like CURRENCY)
8 bytes total = same as DECIMAL/VARIANT-VT_DECIMAL shape
Operator overloads: +, -, *, /, MOD, comparisons, conversions to/from DOUBLE/LONG/QUAD

Raymond Leech

I do a lot of business programming, and have used both currency and currencyx depending on the problem.
  •  

José Roca

I have implemented the Currency and Decimal numeric data types in FreeBasic.

CMoney: CMoney is a wrapper class for the CURRENCY data type. CURRENCY is implemented as an 8-byte two's-complement integer value scaled by 10,000. This gives a fixed-point number with 15 digits to the left of the decimal point and 4 digits to the right. The CURRENCY data type is extremely useful for calculations involving money, or for any fixed-point calculations where accuracy is important.

https://github.com/JoseRoca/AfxNova/blob/main/docs/Numeric%20Datatypes%20/CMoney%20Class.md


  •  

José Roca

CurrencyX, the one with 2 decimals only, can`t be implemented using the CURRENCY data type. I could implement it easily in FreeBasic using the DECIMAL data type, but I will lose the internalization features offered by CURRENCY. In Spain, for example, we use "." as the thousands separator abd "," as the decimal separator, the opposite tha in EE.UU.

For example:

DIM cur AS CMoney = 12345.1234
PRINT cur.FormatCurrency   --> 12.345,12 € (Spain)

  •