Format "00.00" and Round problem

Rick, I’m trying to understand your code. I’m new to code and Xojo, so that will take a while.

I think that your code change the decimal number to int64, but I don’t understand why this:

MsgBox a.Load(1.00499).Round.ToText

report 1.01

I see intVal As Int64.
I see the Constructor intVal = d @ 10000

The RoundB() is there now. What’s occurring with 1.00499 is the following, Money works with 4 fixed decimals, it rounds the loaded number first so 1.00499 is loaded as 1.0050, then you ask round() (round to cents) and it becomes 1.01
With RoundB() it would become 1.00

Thank you. A lot to learn.

One of the greatest features of Money is that the number stored there, is an Integer (Int64), exposed with AsInt, that you can store anywhere with few bytes, in any database that accept an Integer field, guaranteeing it’s value doing integer math, any time. Sums and subtractions occurs with exact cents without cents differences exposed by floating numbers after hundreds of them. The integer contains 4 fixed decimals, so 12345 is the equivalent to 1.2345. When you do a:
m.AsInt=12300
Dim d As Double = m.AsDbl
// d will have 1.2300000
MsgBox m.ToText // 1.23
m.AsDbl = 1.00499
MsgBox m.AsInt.ToText // 10050

Richard: n total leaked bytes increases with each leak

compare with next iteration after clicking a web segmented control or using currency class or move through your app doing user things.

if you put it in a script and run it in a terminal to loop every 5 seconds you’ll get a helpful “leak” monitor when you change pages in your app and run reports, click buttons etc. or to test that new library you’re thinking of using (you get a free leak history).

This is a critical part of any app deployment - you need to know if that new/updated library is going to leak your app to death.

Rick: great work (just wish it wasn’t necessary)

Thanks. Me too.

New version. Forget the older one. This now complies to IEEE Standard 754, section 4. Banker’s rounding is the default for the money class but arithmetic options are present for special needs (like LoadA(), RoundA(), RoundCentsA()).

Now m.Load(1.5555).Round() → 2 and m.Load(1.5555).RoundCents() → 1.56

There are more methods, check the code.

I’ve stopped most, if not all, memory leaks in my Decimal Plugin. Version 3.6 can be downloaded with

http://delaneyrm.com/DecimalPlugin.zip

Bob