Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
252 views
in Technique[技术] by (71.8m points)

formatting - how to convert a string to float with 2 decimal characters (vb.net)

I need to load a float with 2 demic characters to the database but I couldn't find the solution. This is my code where I read a string from a text sheet.

row("AmountWithoutVAT") = String.Format("{0:0.00}", line.Substring(114, 8))

UPDATE: This is my complete code ... I read from a file some values to load then in the database ... I read from a file a value like 3050 but I have to write it in the file like 30.50

Private Sub importSpeKM(ByRef pathname As String)
    Dim KMasterTable As DataTable
    Dim row As DataRow

    dsToImport = DB_SQL.OpenDataset("select * from KMaster2 where 1=2", "KMasterID")

    KMasterTable = dsToImport.Tables(0)

    Dim varcomodo As String = ""
    Dim datafile As Date
    'Dim filedate As Date
    Dim ret As Integer
    Dim culture As CultureInfo = Nothing
    culture = CultureInfo.CreateSpecificCulture("fr-FR")
    Using stream As New StreamReader(pathname)
        Dim newline As String = stream.ReadLine
        varcomodo = newline.Substring(42, 10)
        datafile = CDate(varcomodo)
        For Each line As String In File.ReadAllLines(pathname)

            If line IsNot Nothing And line.Substring(0, 1) <> "H" And line.Substring(0, 1) <> "F" Then
                row = KMasterTable.NewRow()
                row("DataKMaster") = datafile
                row("ContoAutostrade") = line.Substring(47, 9)
                row("TipologiaSupporto") = line.Substring(56, 2)
                row("CodiceSupporto") = line.Substring(58, 10)
                row("AmountWithoutVAT") = Double.Parse(line.Substring(114, 8), culture)
                row("VatAmount") = line.Substring(130, 2)
                row("AmountIncludingVAT") = Double.Parse(line.Substring(132, 8), culture)
                row("MonthOfCompetence") = line.Substring(178, 7)
                row("P_IVA") = line.Substring(202, 12)
                row("Targa") = line.Substring(219, 7)
                KMasterTable.Rows.Add(row)
            End If

        Next

        ret = DB_SQL.SetDBfromDataset(dsToImport, "KMaster2")

        KMasterTable.AcceptChanges()


    End Using
End Sub
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...