Return the number to at least 2 decimal places.

Qj123

New Member
Joined
Aug 27, 2014
Messages
2
Hi all,

Is there possible by using VBA to convert to number to at least 2 decimal places if the original number is an integer or only 1 decimal place and remain unchanged if more than 2 decimal places.

Some Example:

BeforeAfter
10.9910.99
1515.00
65.77765.777
187.3187.30
123.3686123.3686
7070.00

<colgroup><col><col><col></colgroup><tbody>
</tbody>

Thank a lot.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Roderick_E

Well-known Member
Joined
Oct 13, 2007
Messages
2,051
Format(210.6, "#,##0.00")would return '210.60'
Format(210.6, "Standard")would return '210.60'

<TBODY>
</TBODY>
 
Upvote 0

joeu2004

Banned user
Joined
Mar 2, 2014
Messages
3,080
Office Version
  1. 2010
Platform
  1. Windows
Is there possible by using VBA to convert to number to at least 2 decimal places if the original number is an integer or only 1 decimal place and remain unchanged if more than 2 decimal places.

There are two separate issue; not sure which you mean.

In VBA:
Format(number,"0.00############")
range.NumberFormat = "0.00############"

In Excel, Custom format 0.00############.

You need to decide the max decimal places. That allows for up to 14 decimal places total.
 
Upvote 0

Qj123

New Member
Joined
Aug 27, 2014
Messages
2
There are two separate issue; not sure which you mean.

In VBA:
Format(number,"0.00############")
range.NumberFormat = "0.00############"

In Excel, Custom format 0.00############.

You need to decide the max decimal places. That allows for up to 14 decimal places total.

Yes i asking formula to solve both 3 scenario below:

1) integer to 2 decimal place (ex 1 to 1.00)
2) number with 1 decimal place to 2 decimal place (ex 1.1 to 1.10)
3) number > 2 decimal place remain unchanged (ex 1.1111 to 1.1111)

By using this

Format(number,"0.00############")
range.NumberFormat = "0.00############"

It solve my problem.
 
Upvote 0

Forum statistics

Threads
1,191,535
Messages
5,987,157
Members
440,082
Latest member
belodelokelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top