Code example for Scanner

Methods: nextBigDecimaluseLocale

0
        s.useLocale(Locale.ENGLISH);
        assertEquals(new BigDecimal("1.234E12"), s.nextBigDecimal());
        assertEquals(new BigDecimal("-4.567E14"), s.nextBigDecimal());
        assertEquals(new BigDecimal("1.23456789E-5"), s.nextBigDecimal());
 
        s = new Scanner("NaN");
        try { 
            s.nextBigDecimal();
            fail("Should throw InputMismatchException");
        } catch (InputMismatchException e) {
            // Expected 
        } 
 
        /* 
         * Different locale can only recognize corresponding locale sensitive 
         * string. ',' is used in many locales as group separator. 
         */ 
        s = new Scanner("23,456 23,456");
        s.useLocale(Locale.ENGLISH);
        assertEquals(new BigDecimal("23456"), s.nextBigDecimal());
Experience pair programming with AI  Get Codota for Java