0

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

May 08, 2017 at 03:36 PM

75

Former Member

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.

Former Member May 08, 2017 at 03:59 PM
0

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

Show 1 Share

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

Abhilash Kumar
May 08, 2017 at 03:48 PM
0

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

Share
Abhilash Kumar
May 09, 2017 at 09:04 AM
0

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

Share
Former Member May 09, 2017 at 08:27 AM
0

Hello Ian

Worked beautifully, thank you!

Share
Former Member May 09, 2017 at 02:45 PM
0

Hi Abhilash

Thank you also for your imput!

Share