Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting demicals to words

Status
Not open for further replies.

cuetzpalin

Programmer
Jun 5, 2002
99
US
I'm writing reports that need to display numbers with decimal places to text. For example, 4.50 should be four and one half
 
Should it be "Four and One-half" or "4½"? I have heard of a UFL that does all the common fractions from 1/64th to 63/64ths, but I have never bothered with it.

There is also the ToWords() function, which is most commonly used when printing a check thru Crystal to spell out, in words, the dollar amounnt of the check. This would return "Four Dollars and 50 Cents" however, not exactly what you want.

Your best bet is to try to write your own UFL to do this, or maybe there is one already out there, or maybe someone already has this code.

Good Luck
Software Support for Macola, Crystal Reports and Goldmine
dgilsdorf@mchsi.com
 
dgillz: I think that towords returns Four and 50/100. Since Crystal stemmed from being a check writing program, it makes sense.

If you have 4.37, how would you expect the result? Four and 37 one hundredths?

This might work for you, assuming a two digit decimal precision:

You can parse the left and right side of the decimal and apply the towords to each, then place an explicit " and " between them, and add a " one hundredths" to the right side, producing:

"Four and thirty seven one hundredths"

Kinda close...

You can alter this a bit to make it *round* to halves or quarters, if you need to worry over tht precision, and then conditionally produce the "one half, one quarter" text.

The point is, you can do it, but you'll have to code for it.

-k kai@informeddatadecisions.com
 
I've got a UFL I designed for a US manufacturing company that does numbers down to 32nds. It was specifically designed for ft and ins.

the CR function FttoIns(18.75) returns
"1 ft 6 3/4 ins"

I could create a fraction only version if you were interested. Editor and Publisher of Crystal Clear
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top