Help with ROUND function

I am writing a report with part #, and unit cost off the Item table 27. I am trying to standardize on 2 decimal places.

I tried 2:2 under decimal places for the properties of the field and it didn’t do anything.

I tried the ROUND function but it now leaves no decimal amount only whole dollars.

Is there a way to use ROUND and still keep 2 decimal places?

Thanks in advance,

Greg

Can we see your rounding code?



‘=’



To the nearest value (default)



‘>’



Up



‘<’



Down

RoundedResult := ROUND(“Your Value”, .01,’=’);

Harry,

I put it on the Source Expr. of the report field.

ROUND(“Unit Cost”,2)

Greg

Greg, this will round to even numbers only!

1.01 will round to 2
3.12 will round to 4
4.99 will round to 4 as well.

What the round function in NAV really does is:

ROUND(3.12, 0.01) will execute as follows:

x := 3.133 / 0.01; // = 313.3
x := ROUND(x) // = 313
x := x * 0.01; // = 3.13

That is the reason why NAV receives the “Precision” as second parameter rather than the number of decimals as in other programming languages.

Therefore your “precision” (= smallest amount) can be any decimal like 0.05 as used in Finland quite often.

ROUND(3.133, 0.05) will execute as follows:

x := 3.133 / 0.05; // = 62,66
x := ROUND(x) // = 63
x := x * 0.05; // = 3.15

So this function is much more flexible in NAV than it is in the most other languages.

I had to make the precision a Variable with a value of 0.01 and it works now. Thanks to both Harry and Thomas.

Here is my code:

gsUnitCost:=0;
gsRound:=0.01;

gsUnitCost:=ROUND(“Unit Cost”, gsRound,’>’);

I used gsUnitCost for the report source expression.

yes ROUND(“Unit Cost”,2) 2 isn’t the way to specify 2 decimal places - it would be .01

1 = no decimal places
.1 = 1 decimal place
.01 = 2 decimal places
.001 = 3 decimal places

Another quick question. Can you add the Currency $ to the report field? If so how is it accomplished.

Thanks,

Greg

It’s just visual for the report correct?

SourceExp = ‘$’+format(“Your Decimal Field”)

SourceExp = ‘$’+format(gsUnitCost)

Yes it’s just for the report.

Thanks Harry,

Greg

Harry when I use it I lose the decimal places. The $ sign works great though.

Greg

I’m not sure I know how that’s possible - are you sure your field is wide enough now that the $ has been added.

I’ve tried it here and it works fine.
So your saying the field has 2 but when you change the source exp to ‘$’+format(“your field”) it loses it’s decimals?

[:^)]

I just double-checked it Harry.

Some are 2 dec. places, some are 1 dec. places and a lot of them are 0 decimal places. There is no fixed decimal anymore.

Greg

Here is my code.

0647.Nav.JPG

‘$’+FORMAT(ROUND(“Unit Cost”, .01,’>’))

‘$’+FORMAT(gsUnitCost, 0, ‘<DECIMALS,3>’

Thanks again Harry and Thomas.

I’ll give them a shot.

Greg

This solved it. Thanks again Harry and Thomas.

‘$’+FORMAT(gsUnitCost, 0, '<DECIMALS,3>)

Greg

After making the change all the $0.00 are showing up now. Is there a way I can get them not to print? Before if there wasn’t an amount they wouldn’t show.

Greg

5327.AfterFormat.bmp (576 KB)

Do you want to skip them or Blank them - Have you tried setting
BlankNumber property to BlankZero?

Ok try this - There is a proprty called FORMAT!!

Format → $<Sign,1>
BlankZero-> YES

SourceExp - Back to it’s original Field. The format property should apply the $ for you.
Eample…('unit cost") instead of ‘$’+Format(“Unit Cost”)