Michel Vuijlsteke's weblog

Tales of Drudgery & Boredom.

<cf_fraction>

Een mens komt nog eens oude dingen tegen als hij op Google 2001 zoekt… Brrr, dingen in globale variabelen terugsturen.

cf_fraction v. 1.0
© 1999 by Michel Vuijlsteke, Netpoint NV (michel@netpoint.be)

PARAMETERS
number
number to be converted
precision (default: 5)
necessary precision (digits)
denom (default:0>
use fixed denominator?
table (default:No>
results in table?
font (default:Tahoma)>
font to use in table
fontsize (default:2)>
font size in table
show (default:Yes)>
show result?
DOWNLOAD
CF_FRACTION.ZIP
3,480 bytes Winzip format
ALGORITHM
Click here for the
algorithm used.

Converts numbers with decimals to fractions. Can format the fraction in a table or just in text (see examples below). Returns integer part, numerator and denominator in intpart, num and denom variables.

Required parameter: number to convert.

<cf_fraction number="4.65583">
4 928/1415

Optional parameters: precision, denom, table, font, fontsize, show.

Precision (default:5). Necessary precision in digits:

<cf_fraction number="4.655831" precision="2">
4 21/32 [4.65625]
<cf_fraction number="4.655831" precision="3">
4 61/93 [4.65591397849]
<cf_fraction number="4.655831" precision="4">
4 343/523 [4.65583173996]

Denom (default:0). Overrides precision and gives a result with a fixed denominator.

<cf_fraction number="4.655831" denom="8">
4 5/8 [4.625]
<cf_fraction number="4.655831" denom="32">
4 21/32 [4.65625]
<cf_fraction number="4.655831" denom="25">
4 16/25 [4.64]

Table (default:No). Formats fraction in a table. Requires a 1×1 pixel transparent gif named “0.gif” in an “images” subdirectory (i.e. <img src=”images/0.gif”> should resolve to a file).

<cf_fraction number="4.655831" table="Yes" precision="8">

28810
43929

Font (default:”Tahoma,Arial,Geneva,Helvetica”) and Fontsize (default:2). Font and font size the interger part in the table should have. The fraction will be one size smaller in the same font.

<cf_fraction number="4.655831" table="Yes" fontsize="5" precision="8">

28810
43929

<cf_fraction number="4.655831" table="Yes" font="Times New Roman,Times,Serif" fontsize="3" precision="8">

28810
43929

Show (default:Yes). Overrides all other display parameters: the actual result will not be shown. You can still get at the results by using the variables intpart (integer part), num (numerator) and denom (denominator).

<cf_fraction number="4.655831" show="No" precision="8">
<cfoutput>#intpart# plus #num# divided by #denom#<cfoutput>
4 plus 28810 divided by 43929

1 Comment

  1. Hallo,

    Ik werd via via, op de <cf_fraction UDF geatendeerd. Op de een of andere manier echter krijg ik het niet werkend. Dit is mijn code:

    Invalid value submitted. Try again this time with a number.

    Enter Decimal:

    Result:

    Blijf steeds maar het bericht krijgen dat de website niet getoond kan worden.

    Heeft u wellicht suggesties?

    Alvast bedankt

Zeg uw gedacht