Former Member

# Formula to Set Decimal to 1 if Integer and to 1.00 if Fraction

Hi

I need a formula to set the result of the number of decimal of a division to 1 if integer and 2 if fraction.

Example: If the result is 10.00 then 10

If the result is 0.83 then 0.83

I know this can be done under Format Field, but in this case this formula will be used by another formula, that will concatenate its result.

10|10000 characters needed characters exceeded

Former Member
Posted on May 08, 2017 at 03:59 PM

Hi Abhilash

Thank you for your reply, but as I mentioned, that doesn't seem to work in this case.

The current formula is in a group footer and is as below

TOTEXT (Sum ({@qty_conversion_to_bottles}, {'Sales_Data_'.Customer}),0)& "/"&({@bottles_to_cases})

So I am concatenating a summary and a formula there, and I need a formula for the @bottles_to_cases to return the desidered number of decimals.

In the @bottles_to_cases I have the following division

Sum ({@qty_conversion_to_bottles}, {'Sales_Data_'.Customer})/12

10|10000 characters needed characters exceeded
• Change @bottles_to_cases

Local NumberVAR Bottles:=Sum ({@qty_conversion_to_bottles}, {'Sales_Data_'.Customer})/12;

```Local NumberVAR Bottles:=Sum ({@qty_conversion_to_bottles}, {'Sales_Data_'.Customer})/12;
if bottles - int(bottles)= 0 then totext(bottles, 0) else totext(bottles, 2)```

Ian

• Posted on May 08, 2017 at 03:48 PM

Hi Rony,

Right-click the field > format field > Number tab > Click the Customize button > click the formula button beside 'Decimals' and use this code:

```if currentfieldvalue - int(CurrentFieldValue) = 0 then 0
else 2```

-Abhilash

10|10000 characters needed characters exceeded
• Former Member
Posted on May 09, 2017 at 08:27 AM

Hello Ian

Worked beautifully, thank you!

10|10000 characters needed characters exceeded
• Posted on May 09, 2017 at 09:04 AM

Hi Rony,

Try this code:

```local numbervar btc := {@bottles_to_cases};
if btc - int(btc) = 0 then
btc := totext({@bottles_to_cases},0)
else btc := totext({@bottles_to_cases},2);
TOTEXT (Sum ({@qty_conversion_to_bottles}, {'Sales_Data_'.Customer}),0)& "/"& btc;```

-Abhilash