# Returning two decimal places

#### nayone

##### New Member
Hi I have a function in a workbook that reformats a number, taking out decimal place & replacing it with a comma:

MsgBox ReformatNumber((Sheet1.Cells(1, 1).Value))
& the function :
Private Function ReformatNumber(ByVal Num As Single) As String
ReformatNumber = Replace(Num, ".", ",")
End Function

now this works fine but I am trying to add zeros to the end so if a user enters 1 or 1.2 we get 1,00 & 1,20 not 1, & 1,2 as currently
I have tried Mid(Num, Trim(Len(Num)) -2 1, 1) = "." to identify items & then add zeros but the 'len' command always returns 4? within the function for any length of text??

any pointers as this ones in got me

thx

Alex

### Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
try like this
reformatnumber = replace(format(num,"0.00"),".",",")

Works fine thx very much

If Left(Right(Num, 3), 1) = "." Then
ReformatNumber = Replace(Num, ".", ",")
ElseIf Left(Right(Num, 2), 1) = "." Then
ReformatNumber = Replace(Num, ".", ",") & "0"
Else
ReformatNumber = Num & "," & "00"
'End If

But your code is much neater, thx very much

Alex

Replies
4
Views
98
Replies
7
Views
201
Replies
12
Views
417
Replies
0
Views
501
Replies
4
Views
453

1,196,429
Messages
6,015,207
Members
441,882
Latest member
rcgyuk

### 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.

### Which adblocker are you using?

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

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