VBA, round to 2 decimal places

Bwabwa -  
 dd -
Hello,

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

  1. Gord21 Posted messages 928 Status Member 289
     
    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
    3
    1. Bwabwa
       
      Hello, sorry for giving news so late.
      I just tested the proposed solution and it works perfectly well.
      Thank you! :)
      0
    2. dd
       
      Thank you for this piece of code!!!!
      0
  2. eriiic Posted messages 24581 Registration date   Status Contributor Last intervention   7 281
     
    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
    2
    1. Bwabwa
       
      Hello, =D this solution works too =D thanks!
      but I will use "round" instead because it rounds.
      But thanks anyway.
      0