Decimal round down/up

I’ve an error with the calculation for the weigh charge below. the result should always rounded up the weight to the nearest KG.Requirement- round down for weight with the decimal of less than 0.100 and only round up weight with decimal of equal or more than 0.100

simple working on form:

3fields created as below:

1)MyMetricsVolume field(input translation-@getfiled(“myMetricVol1”)*200

2)Calculation field - (input translation-

@If((@Sum(@Integer(@GetField(“getChargeableWeight”)) - @GetField(“MyMetricsVolume”)) = 0) | (@Sum(@Integer(@GetField(“getChargeableWeight”)) - @GetField(“getChargeableWeight”)) = 0) ;

@Do(

@Integer(@GetField(“getChargeableWeight”))

); @Integer(@GetField("getChargeableWeight) + 1)

)

3)getChargebaleWeight field (input translation -

@Max(ActualWeight ; MyMetricsVolume)

Result:

Actual Weight(KG)- 101.000 (MANUAL INPUT)

Volume(m3) - 0.545

Chargeable Weight(KG) - 110.00

The correct charge should be 109 instead of 110. the calculation for the metrics above 0.545 multiply by 200 is 109.

I cant see the problem occurred in this line:

@Do(

@Integer(@GetField(“getChargeableWeight”))

); @Integer(@GetField("getChargeableWeight) + 1)

)

can anyone assist to take a look on the decimal rounded down and up issue? thanks

Subject: decimal round down/up

First, simplify. There’s no reason to use @GetField unless the fieldname is a variable. Just use the field name itself (without quotes). Second, unless there’s a reason to expect a multiple value in getChargeableWeight, there’s no reason to have @Sum in there at all. As a matter of style, never name a field in a way that can be confused with a function or method; field names are descriptive, not functional. That said, your three formulas boil down to this:

MyMetricsVolume:

myMetricVol1 * 200

getChargeableWeight:

@Max(ActualWeight ; MyMetricsVolume)

Calculation:

@Integer(getChargeableWeight + 0.9)

And these are the field formulas for computed fields, not input translations (which only apply to editable fields). Do note, though, that since you can’t represent most decimal fractions exactly in binary, and floating-point math is done in binary, you may have to fine-tune the 0.9 value to make it reliable (like 0.900001 or something).

And you will, of course, want to include checks to make sure that the fields these formulas depend on have numerical values so the formulas don’t error out. It’s up to you whether they compute to 0 or to the empty string when they’re invalid.

Subject: decimal round down/up

okay. tested it seems to be working fine as of now. but im having another round issue with the below codes:

@Round(@GetField(“ShipAmount”) * @GetField(“MonthlyIndexS”);0.01)

my standard monthlyIndex charge is 19.00% or 19.50%

one of the scenario that populated wrongly which is the amount does not round up. example below:

shipAmount=231.00

monthlyIndex=19.50%

Amount charges for monthlyindex charge=45.045

but the system populated as 45.04 which is not round up.

If the below codes formula is change to:

@Round(@GetField(“ShipAmount”) * @GetField(“MonthlyIndexS”);0.05) <— instead of 0.01 the amount charges would show correctly as 45.05 rounded up.

can advise what decimal should I amend? 0.05 or 0.01 ? or 0.001 or 0.005

Subject: RE: decimal round down/up

“Banker’s Rounding” always goes to the nearest even number when you give it a 5 to work with. That’s the way it’s supposed to work. 1.5 rounds up to 2, and 2.5 rounds down to 2. Over a large number of rounding operations, the errors cancel out.

If you want the behaviour to be different, you’ll need to write your own rounding function.

Subject: RE: decimal round down/up

thanks. I tried with the 0.001 in a number field and its working fine with it.