Formatting a Number with an Integer Picture Rounds Up

Hi !
Can you please tell me why such a strange result is obtained ?

  Message(Format(999999.99,@n14))   ! = '1,000,000' ?!!!

What are you expecting?
You’re giving it an integer format picture and getting back an integer. Appropriately rounded.

Do you want the decimal (@n12.2) or truncated integer (999,999) ?

Why? I don’t want hidden rounding! I didn’t set any rounding rules.
Here, the fractional part should simply be discarded. :man_shrugging:

Dunno if relevant, but the help under DECIMAL data types says

DECIMAL
A packed decimal floating point number.
[…]
places
A numeric constant that fixes the number of decimal digits in the fractional portion (to the right of the decimal point) of the variable. It must be less than or equal to the length parameter. If omitted, the variable will be declared as a math based integer. As a result, when places is omitted or zero, fractional values are rounded up.

Try searching the help for INT(truncate fraction)

The INT procedure returns the integer portion of a numeric expression. No rounding is performed, and the sign remains unchanged.

Probably not. Why DECIMAL? You can view the help for REAL (SREAL, PDECIMAL, etc.).
No data type is specified here and no implicit data type conversion is performed.
It’s just that the FORMAT() operator is not working correctly. :cry:

I’m not certain that it is incorrect.
You are asking it to display your number, which has decimals, but to display it as an integer number. That would imply rounding. So I think it’s working correctly using your whole number.
If you want the number to be truncated at the decimal, you need to seperate the integer portion to display.

No! I’m asking you to display a number without a fractional part, rather than changing its value. If I want to display a number as an integer, then everything is fine here.

lVar Long,Auto
Code
lVar = 999999.99
Message(Format(lVar,@n14))   ! = '999,999' OK !
!Message(Format(999999.99,@n14))   ! = '1,000,000' ?!!!

Not realy clear for me, what you want to do…

lVar = 999999.99 ! lVar is LONG, then it makes no sense

For me: lVar = Round(someNumber, someFormatyouWant)

Thanks ! I know how to round a number.
Here the task is to get an adequate result when formatting arbitrary values.

Genricke, it’s not a bug, it’s a feature. :confounded_face:

Use Message(Format(int(999999.99),@n14))

2 Likes

I was getting to a similar conclusion :slight_smile:

FORMAT(INT(999999.99), @N10.0)

I was looking at this in .NET and it has a function to address that. Maybe @Bruce can joy us adding some of this in String Theory

String.Format(“{0:N0}”)

https://stackoverflow.com/questions/105770/net-string-format-to-add-commas-in-thousands-place-for-a-number

The list of features is already longer than the list of promises in C12 (necessarily AI). :thinking:

It seems that in this case rule #3 applies (with 0 decimal places), see “BCD Conversion” help topic:

String(@Nx.y) = BCD
The BCD value is rounded to y decimal places, the result is fitted into the pictured string. If overflow occurs, an invalid picture (####) results.