1. Registered User
Join Date
May 2003
Posts
144

I have a report that shows the total number of serving. I have 10 customers and each of them is served '1/8' pie. How can I get the report to show '1 2/8' pie? Help.

Thanks

SHK

2. Purveyor of Discontent
Join Date
Mar 2003
Location
The Bottom of The Barrel
Posts
6,102
use mod to pull your fraction into a parsed string. IE CInt([total servings] / 8) & " " & [total servings] mod 8 & "/8 pie"
Last edited by Teddy; 01-20-05 at 15:01.

3. Cavalier King Charles
Join Date
Dec 2002
Location
Préverenges, Switzerland
Posts
3,740

dim myT as integer
dim myB as integer
dim myN as single
dim myS as string
myT = 10
myB = 8
myN = myT / myB
myS = cstr(int(myN)) & " " & cstr(myN mod 8) & "/" & cstr(myB)

izy
Last edited by izyrider; 01-20-05 at 13:53. Reason: sorry Teddy: my slow typing again !

4. Cavalier King Charles
Join Date
Dec 2002
Location
Préverenges, Switzerland
Posts
3,740
hmmmm. can that idea run into issues with float imprecision????

maybe this is better done with integer math:

dim myT as integer
dim myB as integer
dim myN as integer
dim myS as string
myT = 10
myB = 8
myN = myT \ myB
myS = cstr(myN) & " " & cstr(myT - (myN * myB)) & "/" & cstr(myB)

type carefully! i really do mean \ and not /

izy

5. Registered User
Join Date
May 2003
Posts
144
First of all. Thanks for the formula. It works except that I am now facing another problem where some of the customers are served 1/8 pie, some of them are served 1/4 pie, and some of them get the whole pie. Any idea how can I make this work? Help. Please.

Thanks

SHK

6. Purveyor of Discontent
Join Date
Mar 2003
Location
The Bottom of The Barrel
Posts
6,102
how many 1/8's is a 1/4?

See where I"m going here?

You know how to convert the fractions, explain how to the computer.

7. World Class Flame Warrior
Join Date
Jun 2003
Location
Ohio
Posts
12,595
Here is a function for SQL Server. You can copy the logic for Access VB if you like:

Code:
```CREATE function MixedFraction(@Numerator int, @Denominator int)
returns varchar(20) as
begin
--blindman, 1/21/05
--returns a simplified mixed fraction from the supplied Numerator and Denominator

--test variables
-- declare	@Numerator int
-- declare	@Denominator int
-- set	@Numerator = 27
-- set	@Denominator = 18

declare	@Counter numeric(16,8)
set	@Counter = 1

while	(@Counter <= @Numerator and @Counter <= @Denominator)
begin
set	@Counter = @Counter + 1
while	((@Numerator/@Counter) = cast(@Numerator/@Counter as int)
and
(@Denominator/@Counter) = cast(@Denominator/@Counter as int))
begin
set	@Numerator=@Numerator/@Counter
set	@Denominator=@Denominator/@Counter
end
end
return	isnull((cast(nullif(@Numerator/@Denominator, 0) as varchar(20)) + ' '), '') + cast(@Numerator % @Denominator as varchar(20)) + '/' + cast(@Denominator as varchar(20))
end```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•