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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Format(210.6, "#,##0.00")would return '210.60'
Format(210.6, "Standard")would return '210.60'

<TBODY>
</TBODY>
 
Upvote 0
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
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,214,878
Messages
6,122,062
Members
449,064
Latest member
scottdog129

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
Back
Top