PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: CMoney - Money data type  (Read 360 times)

JosÚ Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3255
CMoney - Money data type
« on: December 15, 2019, 12:11:52 PM »

Code: [Select]
' ########################################################################################
' Microsoft Windows
' File: CMoney.inc
' Contents: Money data type.
' Compiler: FreeBasic 32 & 64-bit
' Written in 2019 by JosÚ Roca. Freeware. Use at your own risk.
' Notes: Because it uses a DECIMAL structure as the underlying data type, the largest
' possible value is +/-792,281,625,142,643,375,935,439,503.35 when using two decimal places.
' However, the formatting functions, FormatCurrency and FormatNumber can only return a
' maximum value of +/-922,337,203,685,477.58 because they use a currency data type. For
' greater values, you can format the returned string by yourself.
' The number of decimal places defaults to 2, but you can choose between 0-9 by defining
' them before includind CMoney.inc, e.g. #define AFX_CMONEY_DECIMAL_PLACES 4. If you choose
' more than 9 decimal places, the output will be truncated.
' The locale identifier defaults to 1033 (US), for consistency with FreeBasic numeric
' data types, but you can change it by defining it before including CMoney.inc, e.g.
' #define AFX_CMONEY_LCID 1031 (Spain). The locale identifier (LCID) instructs the methods
' of this class about input and output string should be treated. For example, if you choose
' the Spanish LCID, the formated string input and output will us a comma, instead of a point,
' as the dcima˝ separator, and a point, instead of a comma, as the thousands separator.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

Usage example:
Code: [Select]
'#CONSOLE ON
#INCLUDE ONCE "Afx/CMoney.inc"
USING Afx

DIM c AS CMoney = 12345.12
print c
c = c + 111.11
print c
c = c - 111.11
print c
c = c * 2
print c
c = c / 2
print c
c += 123
print c
c -= 123
print c
c *= 2.3
print c
c /= 2.3
print c
DIM c2 AS CMoney = c
print c2
DIM c3 AS CMoney = c * 2
print c3
DIM c4 AS CMoney = c3 / 2
print c4
DIM c5 AS CMoney = "1234.78"
print c5
DIM c6 AS CMoney
c6 = "77777.99"
print c6
DIM c7 AS CMoney
c7 = c6
print c7
DIM cx AS CMoney
FOR i AS LONG = 1 TO 1000000
   cx += 0.01
NEXT
PRINT "0.01 added 1,000,000 times = "; cx


PRINT
PRINT "Press any key..."
SLEEP

Documentation: https://github.com/JoseRoca/WinFBX/blob/master/docs/Numeric%20datatypes/CMoney.md
« Last Edit: December 15, 2019, 02:35:02 PM by JosÚ Roca »
Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9214
  • Windows 10
    • PlanetSquires Software
Re: CMoney - Money data type
« Reply #1 on: December 16, 2019, 09:36:34 AM »

Thanks Jose - looks like another great addition to the library that extends the use of the DECIMAL code. I will have a lot of uses for this class.

Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer