# Android Questionfloat decimal point

#### sohail786

##### Member
Hi,
how to convert float N1 =345.34567 to 2 decimal point

N1= 345.34 results i want.

Thanks

#### emexes

##### Expert
how to convert float N1 =345.34567 to 2 decimal point

N1= 345.34 results i want.

Not rounded to 345.35 ?

#### Mahares

##### Expert
Longtime User
B4X:
``````Dim N1 As Float =345.34567
Dim s As String = NumberFormat(N1, 1, 2)
Log(s)  '345.35

Dim s As String =NumberFormat2(N1,1,2,2,False)
Log(s)  '345.35

Dim s As String = NumberFormat(Ceil(N1*100)/100, 1, 2)
Log(s)  '345.35

Dim s As String = NumberFormat(Floor(N1*100)/100, 1, 2)
Log(s)    '345.34  ' here is the answer the OP wants``````

#### Xfood

##### Expert
try something like this
Log(InteroDecimale("345.34567",".",2)) ' 345.34
B4X:
``````Sub InteroDecimale(Numero As String,Separatore As String,Decimali As Int) As String
'numero = 12345.6789
Dim FormattoNUmero As List =Regex.Split("\" & Separatore, Numero)
Dim ritorno As String
ritorno=FormattoNUmero.Get(0)

If Decimali > 0 Then
ritorno = ritorno & Separatore & Left(FormattoNUmero.Get(1),Decimali)
End If
Return ritorno
End Sub

Sub Left(Text As String, Length As Int)As String
If Length>Text.Length Then Length=Text.Length
Return Text.SubString2(0, Length)
End Sub``````

Replies
6
Views
189
Android Question B4XPlusMinus Decimal Point
Replies
5
Views
817
B4A Library ShapePoints
Replies
0
Views
2K
Replies
4
Views
2K