We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

# Need to output number with 12 decimal places

on
Medium Priority
2,018 Views
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?

Comment
Watch Question

## View Solution Only

Senior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Commented:
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
CERTIFIED EXPERT

Commented:
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;

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.
CERTIFIED EXPERT

Commented:
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.

Commented:
No problem Elrond - either will work.  Just keep mine in mind if you ever expand beyond 3 digits before the decimal.
CERTIFIED EXPERT

Commented:
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)));
``````
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile