Android Question NumberFormat error

Discussion in 'Android Questions' started by micro, Jul 14, 2015.

  1. micro

    micro Well-Known Member Licensed User

    Hi to all
    why NumberFormat not work?

    Code:
    Dim f As Double = 60 / (DateTime.TimeParse(oraattuale) - DateTime.TimeParse(orapemem)) / 1000
     mediaminuto = 
    NumberFormat(f, 11).Replace("."",")
    The result in f is correct but mediaminuto is always 0,0
     
  2. DonManfred

    DonManfred Expert Licensed User

    What is the value of
    oraattuale
    and
    orapemem
    ?
     
  3. micro

    micro Well-Known Member Licensed User

    oraattuale always > of orapemem
    example "10:12:02" and "10:12:33"
    but repeat, the value in f is correct.
     
  4. LucaMs

    LucaMs Expert Licensed User

    Non mi sembra corretta f; tu vuoi ottenere una media al minuto, quindi devi dividere il tempo trascorso per 60000. Inoltre, ti serve tutto in formato stringa?
    Normalmente è meglio usare i Long: oraattuale = DateTime.Now

    I think f shoud be:

    Dim f As Double = (DateTime.TimeParse(oraattuale) - DateTime.TimeParse(orapemem)) / 60000
    ' Do you need orapemem be a string? Can you not use a Long like StartTime = DateTime.Now?

    Also, you should not use that Replace (eventually, you should use AHNumeric in AHLocale library)

    Anyway, what is the log of:
    log(NumberFormat(f, 1, 1))
    ?
     
    Last edited: Jul 14, 2015
  5. micro

    micro Well-Known Member Licensed User

    Yes, oraattuale and orapemem are string.
    you're right, it's easier to divide to 60000 and not in two steps (are test to get the first results in seconds)
    In b4j work fine, i reported bad the code, that 1000 should be in parentheses.....
    Appena posso correggo e riprovo

    Thanks
     
  6. micro

    micro Well-Known Member Licensed User

    this is the right code
    Code:
    Dim f As Double = 60 / ((DateTime.TimeParse(oracompleta) - DateTime.TimeParse(orapesomem)) / 1000)
    Dim s As String = NumberFormat(f, 11)
    mediaminuto = s.Replace(
    "."",")
    Is incorrect / 60000.
     
  7. LucaMs

    LucaMs Expert Licensed User

    Yes, you're right.

    If you want your app works "everywhere", you should not use that replacement.
     
  8. LucaMs

    LucaMs Expert Licensed User

  9. micro

    micro Well-Known Member Licensed User

    Grazie LucaMs.
     
Loading...