Solved

Need to output number with 12 decimal places

Posted on 2006-10-26
6
1,731 Views
Last Modified: 2009-11-17
I have a number with 15 significant digits, 12 of them to the right of the decimal point. (I'm using CR built into VS 2003.) It's stored in the database as a Decimal (though I could change that to a Double if that would make a difference). Crystal Reports apparently has a limit of 10 decimal places that it will display, whether I select the decimals in the Format options of the field or use CStr(number, places) in a formula field (if places is > 10, I get the error: "The number of decimal places is too large or not an integer"). I don't need to do any math on the field in the report, so I'd be happy to convert the field to a string, but I can't figure out a way to do that while keeping all the decimals. Any suggestions?

0
Comment
Question by:ElrondCT
  • 3
  • 2
6 Comments
 
LVL 100

Accepted Solution

by:
mlmcc earned 250 total points
ID: 17816642
Not sure if this will work or not

Add a formula to the report in the section where you want to display the number
CLick INSERT --> FORMULA
Click NEW (may be a right click)
Name - MyNumber
Formula
StringVar MyNumberString;
StringVar FinalNumberString;

MyNumberString := ToText({YourNumberField} * 100,10)
FinalNumberString := Left(MyNumberString,3) & "." & Mid(MyNumberString,3,2) & Right(MyNumberString ,7)
FinalNumberString

Save the formula
CLose the formula editor

Drag the formula onto the report

mlmcc
0
 
LVL 42

Expert Comment

by:frodoman
ID: 17819442
I tried mlmcc's formula and it didn't work correctly.  On the right track, but part of the problem is that it will have commas in the totext conversion that will mess up the string you build.  You can do it w/out the commas with this formula - I wrote it so that it'll return 12 decimal places and will handle any number of digits (>0) preceeding the decimal:

stringVar MyNumberString;
stringVar FinalNumberString;
numberVar BeforeDecimal := len(ToText({YourNumberField},0,''));
MyNumberString := ToText({YourNumberField} * (10^12),0,'');
FinalNumberString := left(MyNumberString, BeforeDecimal) + '.' + right(MyNumberString, 12);
FinalNumberString;


frodoman
0
 
LVL 20

Author Comment

by:ElrondCT
ID: 17819670
Thanks. I've never seen a multi-line Crystal formula before; I didn't know one could do that, and so of course knew nothing of the syntax. It did need a bit of editing; most significantly, the default ToText puts commas in as thousands separators. But I found how to reformat it to keep those out. What I ended up with was:

StringVar MyNumberString;
StringVar FinalNumberString;

MyNumberString := ToText({Header.fldCapRate} * 100,"#####.##########",10);
FinalNumberString := Left(MyNumberString,3) & "." & Mid(MyNumberString,4,2) & Right(MyNumberString,10);
FinalNumberString

I post it for the benefit of others who may run into this kind of issue in the future.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 20

Author Comment

by:ElrondCT
ID: 17819822
Thanks for your efforts, frodoman (obviously, we're both Tolkien fans!). I'd already completed my tweaks before I saw your post. Looks to me like either way would work.
0
 
LVL 42

Expert Comment

by:frodoman
ID: 17820686
No problem Elrond - either will work.  Just keep mine in mind if you ever expand beyond 3 digits before the decimal.
0
 
LVL 20

Author Comment

by:ElrondCT
ID: 24417850
An update to this thread a couple of years later, for anyone who might look at this at a future date:

It turns out that this won't properly handle values that are less than 1; the needed zeroes both before and (potentially, and more seriously) after the decimal point will disappear. So one more tweak was needed:

(This doesn't deal with the potential situation Frodoman noted of a value more than 999, for which the code he described would be needed merged in with this. But I don't need to worry about that in my particular situation, which is dealing with interest rates. I don't plan to deal with Zimbabwean inflation.)


StringVar MyNumberString;

StringVar FinalNumberString;
 

MyNumberString := ToText({Header.fldCapRate} * 100, "#####.##########", 10);

FinalNumberString := IIf({Header.fldCapRate} < 1, "0." & Mid(ToText({Header.fldCapRate} * 10^12 + 10^12, "############"), 2, 12), 

        TrimLeft(Left(MyNumberString, 3) & "." & Mid(MyNumberString, 4, 2) & Right(MyNumberString, 10)));

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now