Controlling decimal digits

J

John

Hi

I have a few numeric hours appear on a report like this;

2
9.75
12.5

This is all fine but when a number like 1.83333 appears I only would like it
to limit to two decimal places as 1.83. How can I achieve this?

Thanks

Regards
 
J

John W. Vinson

Hi

I have a few numeric hours appear on a report like this;

2
9.75
12.5

This is all fine but when a number like 1.83333 appears I only would like it
to limit to two decimal places as 1.83. How can I achieve this?

Thanks

Regards

Set the Format to #.00; or use the Round() function if you're calculating the
value to round it to two decimals.
 
J

John

Hi John

Thanks. Using #.00 works for 1.83333 to make it 1.83 but for other numbers
2, 9.75, 12.5 it also changes them to 2.00, 12.50. How can I get round that?

Basically the values are hours and it looks good if no zeros show after
decimal if its a complete number.

Thanks
 
J

John

Basically I need formatting applied as below;

Before / After
2 / 2
9.75 / 9.75
12.5 / 12.5
1.83333 / 1.83

Basically if digits after decimal are more than two then round/trim to two
decimal., leave everything else alone.

Thanks

Regards
 
J

John W. Vinson

Basically I need formatting applied as below;

Before / After
2 / 2
9.75 / 9.75
12.5 / 12.5
1.83333 / 1.83

Basically if digits after decimal are more than two then round/trim to two
decimal., leave everything else alone.

If just using Round() doesn't work, then I don't know any *simple* way to do
that. You would need some VBA code to parse the number and construct a text
string with the desired decimals.
 
D

De Jager

John said:
Hi

I have a few numeric hours appear on a report like this;

2
9.75
12.5

This is all fine but when a number like 1.83333 appears I only would like
it to limit to two decimal places as 1.83. How can I achieve this?

Thanks

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top