File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,14 +43,17 @@ public static String removeNonDigitCharacters(String toRemove) {
4343 public static long mixedNumberWordToLong (String numberWord ) throws NumberFormatException , ParsingException {
4444 String multiplier = "" ;
4545 try {
46- multiplier = Parser .matchGroup ("[\\ d]+([\\ .,][\\ d]+)?([KMkm ])+" , numberWord , 2 );
46+ multiplier = Parser .matchGroup ("[\\ d]+([\\ .,][\\ d]+)?([KMBkmb ])+" , numberWord , 2 );
4747 } catch (ParsingException ignored ) {}
48- double count = Double .parseDouble (Parser .matchGroup1 ("([\\ d]+([\\ .,][\\ d]+)?)" , numberWord ));
48+ double count = Double .parseDouble (Parser .matchGroup1 ("([\\ d]+([\\ .,][\\ d]+)?)" , numberWord )
49+ .replace ("," , "." ));
4950 switch (multiplier .toUpperCase ()) {
5051 case "K" :
5152 return (long ) (count * 1e3 );
5253 case "M" :
5354 return (long ) (count * 1e6 );
55+ case "B" :
56+ return (long ) (count * 1e9 );
5457 default :
5558 return (long ) (count );
5659 }
Original file line number Diff line number Diff line change 1+ package org .schabi .newpipe .extractor .utils ;
2+
3+ import com .grack .nanojson .JsonParserException ;
4+ import org .junit .Test ;
5+ import org .schabi .newpipe .extractor .exceptions .ParsingException ;
6+
7+ import static org .junit .Assert .assertEquals ;
8+
9+ public class UtilsTest {
10+ @ Test
11+ public void testMixedNumberWordToLong () throws JsonParserException , ParsingException {
12+ assertEquals (10 , Utils .mixedNumberWordToLong ("10" ));
13+ assertEquals (10.5e3 , Utils .mixedNumberWordToLong ("10.5K" ), 0.0 );
14+ assertEquals (10.5e6 , Utils .mixedNumberWordToLong ("10.5M" ), 0.0 );
15+ assertEquals (10.5e6 , Utils .mixedNumberWordToLong ("10,5M" ), 0.0 );
16+ assertEquals (1.5e9 , Utils .mixedNumberWordToLong ("1,5B" ), 0.0 );
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments