B4J Question NumberFormat issue or BUG?

Discussion in 'B4J Questions' started by Cableguy, Mar 16, 2016.

  1. Cableguy

    Cableguy Expert Licensed User

    I have the following code:

    mValue = NumberFormat2(TextField1.Text + StepValue, 1, mDecimals, mDecimals, False)

    where mValue is Double, StepValue and mDecimals are integers defined in the designer...

    Given a mDecimals of value 2, shouldn't this code convert a number like 1.1 to a string like "1.10"??

    I ask because all I get is the same decimal places as the mathematical value (i.e 1 + 0.1 = 1.1) , no mater how I format the number


    [EDIT]

    Seems like using NumberFormat on a variable has a different behaviour than using it directly on a string like a TextField.text, where it works perfect
     
    Last edited: Mar 16, 2016
  2. DonManfred

    DonManfred Expert Licensed User

    Code:
    Log(NumberFormat2(1.1,1,2,2,False)) ' Logs 1.10
    Edit: ok, i tried this with B4A.

    I would guess a bug in B4J
     
    Cableguy likes this.
  3. Cableguy

    Cableguy Expert Licensed User

    see my Edit
     
  4. klaus

    klaus Expert Licensed User

    NumberFormat returns a String !
    But your variable is a Double, the only thing you may achieve is a sort of rounding, but not a display formating.
    To format a number for display you must use a String variable as the return variable and not a Double.
     
    Erel and Cableguy like this.
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