Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need to output number with 12 decimal places

Posted on 2006-10-26
6
Medium Priority
?
1,825 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 101

Accepted Solution

by:
mlmcc earned 1000 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month12 days, 16 hours left to enroll

972 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