Ingreso una operación donde ingreso 0.25 pero me da por respuesta 25.0 , por lo tanto no puedo guardarlo en la base de datos

 Private Sub btningresar_Click(sender As Object, e As EventArgs) Handles btningresar.Click
        tara = CDbl(LblIndicador2.Text)
        PB = CDbl(lblindicador.Text)
        'Calcular el peso:
        PN = Convert.ToDouble(PB - tara)

Dani AI

Generated

Quick summary and a practical fix: the symptom (entering "0.25" and getting "25.0", then failing the INSERT) most often comes from a mismatch between the string format shown in the label and the culture used when converting to a number, or from using formatted strings to build SQL. correctly pointed to a locale/formatting issue; the safest approach is to (1) detect/clean the exact characters coming from the indicator, (2) parse the numeric value explicitly with a known culture, prefer Decimal for precision, and (3) send the value to MySQL as a typed parameter (not a formatted string). 's translation of the original post helps confirm the symptom reported by .

Checklist + code patterns (VB.NET)

  • Log the raw label exactly (for example wrap it in brackets) to reveal hidden spaces, unit text or non-ASCII characters.
  • Extract a pure numeric substring (strip units/thousands separators) and then parse with a chosen culture or InvariantCulture.
  • Prefer Decimal for weights/money and round to the DB scale before inserting.
  • Always use parameterized INSERTs and list the column names so the "number of values must match number of columns" error cannot happen.

Example: extract -> parse -> insert (conceptual VB.NET)

' get numeric part, parse with invariant culture
Dim raw = lblIndicador.Text.Trim()
Dim numberText = System.Text.RegularExpressions.Regex.Match(raw, "[+-]?\d+([.,]\d+)?").Value
Dim value As Decimal
If Decimal.TryParse(numberText.Replace(",", "."), Globalization.NumberStyles.Number, Globalization.CultureInfo.InvariantCulture, value) Then
    value = Decimal.Round(value, 3) ' match DB scale
    ' parameterized insert
    Dim sql = "INSERT INTO yourTable (tare,pb,pn) VALUES (@tare,@pb,@pn)"
    Using cmd As New MySql.Data.MySqlClient.MySqlCommand(sql, conn)
        cmd.Parameters.Add(New MySql.Data.MySqlClient.MySqlParameter("@tare", MySql.Data.MySqlClient.MySqlDbType.Decimal)).Value = value
        ' add other params...
        cmd.ExecuteNonQuery()
    End Using
End If

Notes and cautions

  • Do not format numbers into SQL text; use typed parameters to avoid locale and SQL injection problems.
  • Check the MySQL column type (DECIMAL(p,s) vs FLOAT) and round to the same scale before insert.
  • Avoid changing Thread.CurrentCulture globally; prefer explicit parsing with CultureInfo where the input format is known.

This approach addresses both the parsing/formatting root cause and the common INSERT mismatch error.

Recommended Answers

All 3 Replies

We are an English-only community. Can you please post your question in English so that we can help you? Thanks!

Your language uses "," as decimal separator and "." as thousand separator and that is why instead of retrieving 1/4 (=0.25), CDbl is getting 25. Use double.parse instead, setting the NumberFormat you need:

        Dim ni As Globalization.NumberFormatInfo = Globalization.CultureInfo.CurrentCulture.NumberFormat.Clone
        ni.NumberDecimalSeparator = "."
        tara = Double.Parse(lblindicador2.Text, ni)
        PB = Double.Parse(lblindicador.Text, ni)

Seeing as someone has been kind enough to answer the question despite it not being in Engliah, here's the Google Translate version (for which I cannot be held responsible regarding accuracy...)

"Join one operation where income 0.25 but I get to answer 25.0 , by so much not I can save it in the database of data "

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.