Solved

Need to output number with 12 decimal places

Posted on 2006-10-26
6
1,726 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

23 Experts available now in Live!

Get 1:1 Help Now