Android Question SQLLite return science number

Discussion in 'Android Questions' started by ttsolution, Feb 4, 2015.

  1. ttsolution

    ttsolution Member Licensed User

    Dear all,
    I select price from SQLLite as follow query

    mPrice=Main.SQL1.ExecQuerySingleResult("Select ifnull(PriceWithVAT,0) as PriceWithVAT from ProductPrice Where ItemCode='" & P.ItemCode & "'")

    result : mPrice= 2.04039E7 (but the actual value is 20403831.8)

    When I show the value to EditText, it is 2.04039E7 rather than 20403831.8

    Many thanks for any help

    Jonh,
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    ExecQuerySingleResult returns a string. Seems like it loses precision here. Try to use ExecQuery and get the result with Cursor.GetDouble.
     
  3. ttsolution

    ttsolution Member Licensed User

    I tried with Cursor.GetDouble but same.
    Thanks
     
  4. keirS

    keirS Well-Known Member Licensed User

    Use the NumberFormat function to format the number for display in the Editext.
     
    Erel likes this.
  5. Mahares

    Mahares Well Known Member Licensed User

    Another alternative to Erel and keirS good advice is to use the SUBSTR function like this without having to reformat the result:
    Code:
    Dim mPrice As String
    mPrice=Main.SQL1.ExecQuerySingleResult(
    "Select ifnull(substr(PriceWithVAT,1),0) " _
    "from ProductPrice Where ItemCode='" & P.ItemCode & "'")
    Log(mPrice)
     
    NJDude likes this.
  6. edgar_ortiz

    edgar_ortiz Active Member Licensed User

    You can try:

    mPrice=Main.SQL1.ExecQuerySingleResult("Select cast(ifnull(PriceWithVAT,0) as decimal(10,2)) as PriceWithVAT from ProductPrice Where ItemCode='" & P.ItemCode & "'")

    Regards

    Edgar
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice