9320-ux
9320-ux

Reputation: 3

Display value to a certain number of decimal places in a VBA userform

I'm currently creating a userform in VBA where you input numbers, press calculate, and then the answer is returned in a textbox.

Currently the answer is being displayed to 10+ significant figures (see below). What would I need to do to make my calculated output display only 3 decimal places?

Thanks!


Calculation output example:

Calculation Output Example

Upvotes: 0

Views: 5568

Answers (2)

Plagon
Plagon

Reputation: 3139

Try: TextBox1 = Round(Value, 3)

Upvotes: 1

B Slater
B Slater

Reputation: 340

Format(myAnswer, "0.00") will do it if you want 2 digits after the decimal point, just add more or less 0's after the decimal point in the second argument to change the significant figures.

Here is a website about how to write number formats to use in this function.

Upvotes: 1

Related Questions