Skip to Content
0

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

May 08, 2017 at 03:36 PM

75

avatar image
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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

5 Answers

Best Answer
avatar image
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
10 |10000 characters needed characters left 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

0
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
10 |10000 characters needed characters left characters exceeded
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
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member May 09, 2017 at 08:27 AM
0

Hello Ian

Worked beautifully, thank you!

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member May 09, 2017 at 02:45 PM
0

Hi Abhilash

Thank you also for your imput!

Share
10 |10000 characters needed characters left characters exceeded