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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stumped! Can't explain CStr behavior...

Status
Not open for further replies.

KerryC

Technical User
Apr 9, 2002
36
CA
Hi,

I'm using CR9 and was having some unexpected behavior with the CStr function. So to troubleshoot I created a new function that is just:

CStr(125.34,"000.00")

This is an example directly from the CR online help. The help screen says the result of this should be "125.34" but when I put this formula on a report I get "125.00"

I'm afraid I'm missing something obvious but I've been staring at this too long and thought I should ask for help.

Kerry
 
Perhaps you should state the requirement rather than an unexpected behavior.

If you'd like 2 decimals of precision, use:

cstr(125.34,2)

Not sure why you're getting that result, but try applying the service pack (I don't use that method for formatting).

-k
 
Hi synapsevampire -

It's not exactly the number of decimal places I'm trying to dictate, it's the number of significant figures. I've created a user defined function to create a format string that I thought CStr could use to take care of significant figures. The UDF gives me the format string I want, but CStr doesn't behave like the online example.

Perhaps a better example might be the numbers 0.12534 and 0.01253 which represented to 3 significant figures are 0.125 and 0.0125, respecively. So you see, I cannot use decimal places alone.

The format string for these examples given by my UDF are "0.000" and "0.0000", respectively which according to how I read the online help example should have been what CStr could use to give the correct value. So my question still comes down to why my simple test function CStr(125.34,"000.00") yields "125.00" instead of "125.34" ?

Kerry
 
Dear KerryC,

I think the issue here is that it is setting the format to what you have by global default for number fields.

Look in File/Options/Fields/Number and see what it is set to.

I was able to duplicate the issue you are having and I was able to correct it (sort of) by changing the default format. I didn't expect it to behave this way. I assumed that it would take the actual value, but it appears that the number of decimals of precision are required here.

Why not update your UDF to return the number of decimal places of precision required also so that you return:

"0.000", 3 for example ...

Hope that helps,

ro

Rosemary Lieberman
rosemary-at-microflo.com, Microflo provides expert consulting on MagicTSD and Crystal Reports.

You will get answers more quickly if you read this before posting: faq149-3762
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top