How to make this Java (Android) String substitution? -
i don't understande why not working: (method taken here on so).
private string makesizehumanreadable(int bytes, boolean si) { int unit = si ? 1000 : 1024; if (bytes < unit) homecoming bytes + " b"; int exp = (int) (math.log(bytes) / math.log(unit)); string pre = (si ? "kmgtpe" : "kmgtpe").charat(exp-1) + (si ? "" : "i"); string hr = string.format("%.1f %sb", bytes / math.pow(unit, exp), pre); hr = hr.replace("-1 b", "n.a."); homecoming hr; }
and neither one:-
private string makesizehumanreadable(int bytes, boolean si) { int unit = si ? 1000 : 1024; if (bytes < unit) homecoming bytes + " b"; int exp = (int) (math.log(bytes) / math.log(unit)); string pre = (si ? "kmgtpe" : "kmgtpe").charat(exp-1) + (si ? "" : "i"); string hr = string.format("%.1f %sb", bytes / math.pow(unit, exp), pre); pattern minuspattern = pattern.compile("-1 b"); matcher minusmatcher = minuspattern.matcher(hr); if (minusmatcher.find()) { homecoming "n.a."; } else { homecoming hr; } }
from time time -1 b
request (this normal), never changed in n.a.
(....my question).
does have idea?
here's problem:
if (bytes < unit) homecoming bytes + " b";
when bytes
equals -1 (which less unit
in either case), returns -1 b
without ever getting line hr = hr.replace("-1 b", "n.a.");
.
it improve have 1 return
statement @ end, assign string hr = bytes + " b"
in if
, , add together else
block around next 3 lines. after block, hr.replace()
phone call execute either way, , homecoming value.
java android string substitution string-substitution
No comments:
Post a Comment