Userform textbox as number keeps rounding up or down

RobbieC

Active Member
Joined
Dec 14, 2016
Messages
376
Office Version
  1. 2010
Platform
  1. Windows
Hi there, I have a userform with six textboxes which only accepts numbers

The first textbox is a 'startingDepth' which in this example is '1'

The next 4 input boxes are a 'count' of how many shovel loads make up 0.5 metres

As each of these 4 boxes receive an input, 0.5 is added to the 'startingDepth'

The last textbox is a TOTAL of the 'startingDepth' + 0.5 for each of the 4 boxes (in this example 1 + 0.5 + 0.5 + 0.5 + 0.5 = 3)

This all works fine for a WHOLE number as the 'startingDepth', but if the startingDepth is 1.5, it rounds it down to 1 and if it is 1.8, it will round it up to 2

Is there a way I can convert my initial number to 2 decimal places?

Thanks
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi there, I have a userform with six textboxes which only accepts numbers

The first textbox is a 'startingDepth' which in this example is '1'

The next 4 input boxes are a 'count' of how many shovel loads make up 0.5 metres

As each of these 4 boxes receive an input, 0.5 is added to the 'startingDepth'

The last textbox is a TOTAL of the 'startingDepth' + 0.5 for each of the 4 boxes (in this example 1 + 0.5 + 0.5 + 0.5 + 0.5 = 3)

This all works fine for a WHOLE number as the 'startingDepth', but if the startingDepth is 1.5, it rounds it down to 1 and if it is 1.8, it will round it up to 2

Is there a way I can convert my initial number to 2 decimal places?
I think it would be helpful if you showed us the code that puts the total into that last TextBox.
 
Upvote 0
Hi Rick, sorry, I just answered my own question....

I had:

Code:
dim startingDepth as Integer

which rounds up or down... I have changed it to

Code:
dim startingDepth as Double

which now allows the decimal place to work!
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,748
Members
448,989
Latest member
mariah3

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