Trenera
Trenera

Reputation: 1505

VBA - decimal - format

I need to convert any number to 1 decimal (e.g 243.3). I currently use:

Dim maxi As Double
maxi = data.Cells(11, 7)

maxi = FormatNumber(maxi, 1)

Which is OK if I have 243.4534634, but is a problem when I have integer (e.g. 243). In the later it gives me "maxi" as a integer instead of 243.00

Upvotes: 0

Views: 187

Answers (2)

Gary's Student
Gary's Student

Reputation: 96753

This will get you the value as a String formatted with one decimal place:

Sub OnePlace()
    Set Data = ActiveSheet
    Dim maxi As Double
    Dim maxiS As String
    maxi = Data.Cells(11, 7)
    maxiS = FormatNumber(maxi, 1)
    MsgBox maxiS
End Sub

Upvotes: 1

meta
meta

Reputation: 1

Are you looking for something like Cdec(maxi), which will convert to decimal?

Upvotes: 0

Related Questions