VBA, round to 2 decimal places
Bwabwa
-
dd -
dd -
Hello,
I created a userform where I input data using this method:
The problem is that some prices are too long, with several digits after the decimal point..
I would like to display these prices rounded and without decimals.
How does it work?
I thought about
1 - rounding by applying the rounding function to the 3 concerned price columns, then
2 - inserting the values into the corresponding textboxes using the above code, but it would be necessary to locate the position of the parenthesis and only copy what is before it.
I already thought about Len, Left, IsString... but I'm a beginner in VBA, it's complicated, could you please help me?
Thank you in advance
I created a userform where I input data using this method:
price.Text = Worksheets(1).Range("V" & numLigCourante).Value & " €" The problem is that some prices are too long, with several digits after the decimal point..
I would like to display these prices rounded and without decimals.
How does it work?
I thought about
1 - rounding by applying the rounding function to the 3 concerned price columns, then
2 - inserting the values into the corresponding textboxes using the above code, but it would be necessary to locate the position of the parenthesis and only copy what is before it.
I already thought about Len, Left, IsString... but I'm a beginner in VBA, it's complicated, could you please help me?
Thank you in advance
2 answers
-
Good evening,
Does this solution work for you:price.Text = Round(Worksheets(1).Range("V" & currentLineNumber).Value & " €", 2)
See you later
--
Experience: the name men give to their mistakes.
Oscar Wilde -
Hello,
you can also format, all custom formats are usable.
for example, 2 decimal places:
price = Format([A1], "0.00 €")
or as a whole number:
price = Format([A1], "0 €")
eric