R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

I need to somehow format a Qty field to only show significant digits past the decimal point, trimming any trailing zeros.

(i.e. 4.567 would display 4.567, 4.560 would display 4.56, 4.500 would display 4.5)

thanks!

(i.e. 4.567 would display 4.567, 4.560 would display 4.56, 4.500 would display 4.5)

thanks!

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get this solution by purchasing an Individual license!
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Is it a field on the report or is it in a formula that produces a string?

mlmcc

"The total is : " & CStr({MyValue})

James suggestion should work if you are just displaying the value or in a cross tab.

mlmcc

as per my original post:

(i.e. 4.567 would display 4.567, 4.560 would display 4.56, 4.500 would display 4.5)

in know it sounds crazy, but that's how they want it. I am not very experienced with formulas and local variables in Crystal, so I will try to modify the formulas above. I have some morning commitments, so after that I will work on this problem. thanks for everyone's help.

What isn't working about the formula?

You use that in the CUSTOM FORMAT of a number control the decimal places shown.

You might also have to change the ROUNDING so that it rounds with more significant digits than you might need like at 0.0000000001

If this is just for display then you could convert it to a regular formula.

```
Local NumberVar places;
places := 0;
while Truncate (CurrentFieldValue * 10 ^ places) <> CurrentFieldValue * 10 ^ places do
places := places + 1;
CStr(CurrentFieldValue , places)
```

mlmcc

Formatting to a fixed decimal is no problem. Right click, choose how many decimals you want and viola.

what my customer wants is for a variable number of digits after the decimal with no zeros.

so in a column in the report you might see:

4.56

4.6

6.255

and so on. just no trailing zeros... I know its crazy, but that is what they are asking for...

what my customer wants is for a variable number of digits after the decimal with no zeros.That is _exactly_ what my suggestion should do. What it's doing is changing the number of decimal places in the field format, depending on how many significant digits there are.

James

"A number, or currency amount is required here."

and the cursor goes to the "Local NumberVar places;" statement.

the editor syntax is set to "Crystal Syntax"

suggestions?

Can you post your formula? I used the formula that I posted on a field and it worked fine.

James

Local NumberVar places;

places := 0;

while Truncate (CurrentFieldValue * 10 ^ places) <> CurrentFieldValue * 10 ^ places do

places := places + 1;

CStr(CurrentFieldValue , places)

Just to be clear, here's my formula again (the same thing I posted earlier):

```
Local NumberVar places;
places := 0;
while Truncate (CurrentFieldValue * 10 ^ places) <> CurrentFieldValue * 10 ^ places do
places := places + 1;
places
```

Also, as I mentioned in my earlier post, you should enter the same formula for Rounding in the field format.

James

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trialmlmcc

I didn't pick up on the "Put the same formula in the Rounding AND Decimal formulas".

It works like a charm!

Thanks again

James

thanks again

James

Crystal Reports

From novice to tech pro — start learning today.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get this solution by purchasing an Individual license!
Start your 7-day free trial.

Open in new window

Assuming that that's not a problem, you can give the following a try:

Go into the field format, click Customize on the Number tab, click the formula (X+2) button beside Decimals and enter the following formula:

Local NumberVar places;

places := 0;

while Truncate (CurrentFieldValue * 10 ^ places) <> CurrentFieldValue * 10 ^ places do

places := places + 1;

places

CurrentFieldValue is a special CR function used to reference the value in the field in a formatting formula. You could use the actual field name instead. CurrentFieldValue is particularly handy if you want to use the same format formula for multiple fields. Then you don't have to change the field name in each formula.

What that formula does is multiply the field by increasing powers of 10, until the result without decimals (Truncate) matches the result with decimals. For example, with 4.56, you'd get:

Open in new window

So places ends up set to 2, and you get 2 decimal places in the field format (ie. 4.56).

You'd want to enter the same formula for the Rounding part of the field format, so that CR will also round the field to the correct number of decimals.

James