Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Hello:

I have the following formula in Crystal Reports:

if {IV00101.USCATVLS_5} = "" then

0

else

(Cdbl({IV00101.USCATVLS_5})*1.0)/2.2046

This results in .13. I need it to result in .127 (i.e. no rounding).

How do I accomplish this?

Thanks!

TBSupport

I have the following formula in Crystal Reports:

if {IV00101.USCATVLS_5} = "" then

0

else

(Cdbl({IV00101.USCATVLS_5}

This results in .13. I need it to result in .127 (i.e. no rounding).

How do I accomplish this?

Thanks!

TBSupport

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
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.

FWIW, you could eliminate the test for "" if you use Val, instead of CDbl. Val converts any leading numeric characters in a string to a number. For example, Val ("123abc456") would give you 123. For an empty string (""), you'd get 0. So, your formula could be just one line:

(Val({IV00101.USCATVLS_5})

James

TBSupport

(Cdbl(".28")*1.0)/2.2046

If you try that formula, what result do you get?

Just to make sure, if you're using the "Customize" option in the field format, make sure you set both "Decimals" and "Rounding".

James

I'm just trying to find a way, through modifying the formula, to get Crystal to not round to the second decimal place.

TBSupport

Have you tried

if {IV00101.USCATVLS_5} = "" then

0

else

(Cdbl({IV00101.USCATVLS_5}

or

if {IV00101.USCATVLS_5} = "" then

0

else

Cdbl({IV00101.USCATVLS_5})

mlmcc

If you go to the field format and select the Number tab, there is a Customize button. If you click on that, you can set the "Decimals" (number of digits displayed to the right of the decimal point) and "Rounding" (significant digits to the right of the decimal point). What I was saying in my last post was that you need to set both of those. For example, if you set Decimals to 1.000 (3 places), but leave Rounding set to 0.01 (2 places), .127 would be displayed as 0.130, because the field is set to show 3 decimal places, but it's also set to round to 2.

There are some predefined formatting options with 4 decimal places. You might try one of those first, like -1123.0000 . If the other decimal places show up, then you can use Customize and change both the Decimals and Rounding settings to 3 decimal places.

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 trialYou included a formula in your first post. We (I think I can speak for mlmcc on this) have been assuming that you created a formula in the report that contains only the lines in the formula in your first post, and then you put that formula on the report, and the value that was displayed on the report appeared to be rounded.

But if there is no Number tab in the field format window, then that field is not numeric, but result of the formula that you posted _is_ numeric. So either you're looking at the format for a different field, or there is more to your formula than what you posted here. If you're looking at a different field, how is it related to the formula that you posted? If there is more to your formula, can we see the rest of it?

James

Perhaps the formula is being used in another formula for display.

mlmcc

"Unit Weight: " & {@Unit Weight} & " "&{@pounds and kilos}

Again, though, it doesn't matter. There should be someway to have the Unit Weight formula be ".127" instead of ".13". I can't believe that something that should be very simple is turning into something hard.

TBSupport

"Unit Weight: " & CStr({@Unit Weight},3) & " "& CStr({@pounds and kilos},3)

The 3 is the number of decimals to use

You can also use a format string

"Unit Weight: " & CStr({@Unit Weight},"0.000" & " " & CStr({@pounds and kilos},"0.000")

mlmcc

James

I figured this out. I took the formula that I posted out of the formula that it was originally placed in.

Then, I took the formula that I posted, right-clicked on it, chose "Format Field", choose the Number tab, and then clicked the "Customize" button.

Finally, I chose three decimal places and three places for rounding.

That did it.

Thanks, for your help!

TBSupport

mlmcc,

Are you OK with the point distribution? There was a lot of discussion while we were trying to figure out what was going on.

James

Crystal Reports

From novice to tech pro — start learning today.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

Have you formatted it to show more than 1 decimal?

Right click the field

Click FORMAT FIELD

Click the NUMBER tab

Choose the format you want or click customize

Set decimals to 2 and rounding to .01

mlmcc