# Math converted to text

This topic is 6988 days old. Please don't post here. Open a new topic instead.

## Recommended Posts

Well my logic breaks on this one and I know it can be better also. LineItems holds Quantity (number) of 'eaches' sold. Products holds QtyPerCase (number) of how many are in a case. Joined on ProductID.

Packing Slip requirements: Currently we just display eaches (only the Quantity field). Owner wants it changed to display total 'cases' and 'eaches'. What I have (yep, ugly) ...

Let(

[

cs = Div(Qty; Products::QtyPerCase) ;

ea = Qty / Products::QtyPerCase - cs

]

;

Case(

ea > 0 ; cs & " Cases, " & ea & " Eaches";

cs = 1; cs & " Case";

not cs; ea & " Eaches";

cs & " Cases")

)

If Quantity is 1 and QtyPerCase is 12 it displays as: 0 Cases, .0833333 Eaches. Geez. Need to fix the eaches and I'd like to eliminate the cases portion if it's under a case also. I got myself a bit lost. Does it show?

LaRetta

##### Share on other sites

Try:

Let ( [

cs = Div ( Quantity ; QtyPerCase ) ;

pc = Mod ( Quantity ; QtyPerCase )

] ;

Case ( cs ; cs & " Case" & Case ( cs - 1 ; "s" ) ) &

Case ( pc ; Case ( cs ; ", " ) & pc & " Piece" & Case ( pc - 1 ; "s" ) )

)

And pardon me for changing the vocabulary - I've never heard of "eaches".

If Quantity = 25, you'd get "2 Cases, 1 Each", which to me means "Let's you and I get some beer - 2 cases, one each".

##### Share on other sites

I had tried using Mod() on the ... errr pieces portion. Oh! This means I'm *getting* it but just not quite *getting* it!! YAY!!!

And I couldn't remember how you and JT and Ray split the (s) for single/plural in the Case() portion. Maybe I'll remember it now.

It isn't 'bottles' because sometimes it could be tabs, etc. Eaches is all we could think of - pieces is perfect!

I will thank you in advance for the calculation, Michael. I have absolutely no doubt that it's perfect.

LaRetta

##### Share on other sites

This topic is 6988 days old. Please don't post here. Open a new topic instead.

## Create an account

Register a new account