Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to output number with 12 decimal places

Posted on 2006-10-26
6
Medium Priority
?
1,810 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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…
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

721 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