Android Question NumberFormat error

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
why NumberFormat not work?

Code: Copy
Dim f As Double = 60 / (DateTime.TimeParse(oraattuale) - DateTime.TimeParse(orapemem)) / 1000
 mediaminuto = NumberFormat(f, 1, 1).Replace(".", ",")

The result in f is correct but mediaminuto is always 0,0
 
What is the value of
oraattuale
and
orapemem
?
 
Upvote 0
oraattuale always > of orapemem
example "10:12:02" and "10:12:33"
but repeat, the value in f is correct.
 
Upvote 0
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:
Upvote 0
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
 
Upvote 0
this is the right code
Code: Copy
Dim f As Double = 60 / ((DateTime.TimeParse(oracompleta) - DateTime.TimeParse(orapesomem)) / 1000)
Dim s As String = NumberFormat(f, 1, 1)
mediaminuto = s.Replace(".", ",")

Is incorrect / 60000.
 
Upvote 0
Back
Top