1

Declaration

Dim currDoc As Object
Dim currSheet As Object
Dim cell As Object  
currDoc = ThisComponent
currSheet = currDoc.sheets(0)

Logic

cell.Formula = cDbl(cell.Value)

Desired Output
100,00

Tobi S
  • 145
  • 8
  • You are approaching the problem from the wrong side. Do you want the number in the cell to be formatted (displayed) with two digits after the decimal point? A UDF (as well as the built-in [**=TEXT(...;"0.00")**](https://help.libreoffice.org/7.1/en-US/text/scalc/01/04060110.html?DbPAR=CALC#bm_id3147132) function) can display a number in the desired form, but converts it to a string, further arithmetic operations with this value will be very difficult. Try to explain in simple words what you are trying to achieve, and we will try to explain in not very complicated words how to achieve this. – JohnSUN Aug 12 '21 at 08:07
  • 1
    I am aware of built in functions, but I would like to solve it by code so I could assign the macro to a button and whenever I would like to format a number with 2 decimal places, I just press the button. – Tobi S Aug 12 '21 at 08:32
  • @JohnSUN yes I would like to format the number in the cell with two digits after a decimal point, but I would like to solve it with basic/ by code. – Tobi S Aug 12 '21 at 08:43
  • You already have this button. And there is a key combination too. Try **Ctrl+Shift+1** or the button on the toolbar labeled **0.0** with the tooltip *Format as Number*. Yes, you can do it with code, you will find suitable formatting examples in the books by Andrew Pitonyak. But just believe me, the effort spent will not justify the result, leave this venture. – JohnSUN Aug 12 '21 at 08:49

1 Answers1

1

based on @JohnSUN 's comment: Just add one line for your cell to be formatted:

Cell.NumberFormat = 2 

Table for all Numberformats on page 189

TorbenIT
  • 259
  • 2
  • 12