# Truncate Double to 1 decimal place

I need to truncate to 1 decimal place, not to the whole number. It appears that round, ceil, and floor all go to the appropriate whole number.
I need 2.768 to be formatted as 2.7
When I use

``format(2.768, "-#0.0")``

I get 2.8.
Help appreciated

Got it!

```Dim d As Double d = Floor(0.768 * 10) / 10 Dim s As String = Format(d, "-#0.0")```

Result = 0.7

I think you will need to *10 get the integer part then /10

[quote=394644:@Roger Clary]Got it!

```Dim d As Double d = Floor(0.768 * 10) / 10 Dim s As String = Format(d, "-#0.0")```

Result = 0.7[/quote]

But -0.768 gives you -0.8 unless…

[code] Dim v As Double = -0.768

Dim d As Double
If v<0 Then
d = Ceil(v * 10) / 10
Else
d = Floor(v * 10) / 10
End
Dim s As String = Format(d, “-#0.0”)[/code]

You are correct, Rick. That extra check is needed for negatives

The following works fine and is a bit simpler, albeit less readable:

[code]'dim S as double = 1.23456
dim S as double = -2.34567
dim V as double
dim R as string

V = ((S * 10)\1)/10
R = format(V, “-#0.0”)
msgbox R[/code]

It works regardless of the sign.

[code] dim v as double = -555555555.99999
dim r As Double
dim i As Int64
dim c As Currency

If v<0 Then // nearest double with 1 decimal
r = Ceil(v * 10) / 10
Else
r = Floor(v * 10) / 10
End

// r = -555555555.8999999761581421 — nearest double 55555555.9 achievable from the original
break

r = ((v * 10)\1)/10 // Tricking with implicit integer conversion

// r = -214748364,800000011920929 — Maybe it becomes completely broken
break

i=(v*10) // add 1 decimal and truncate as Int64
c=i/10 // move the decimal point to the correct place -555555555.9 As Currency
r=c // If you move it to a double, it becomes -555555555.8999999761581421 again
break[/code]

yep. Did not think of that. Your method is better for sure.

Thanks both Louis and Rick. Going with

```If v<0 Then // nearest double with 1 decimal r = Ceil(v * 10) / 10 Else r = Floor(v * 10) / 10 End```