## 11821 - High-Precision Number

Moderator: Board moderators

RookiE3
New poster
Posts: 16
Joined: Tue Feb 18, 2014 7:59 pm

### 11821 - High-Precision Number

Can anybody please tell me what am I doing wrong here:

Code: Select all

``````import java.io.BufferedReader;
import java.io.IOException;
import java.math.BigDecimal;

public class Main {

static BigDecimal num, sum;
static String line;

public static void main(String[] args) throws IOException {
while (t > 0) {
sum = BigDecimal.ZERO;
if(line.length() == 1 && line.charAt(0) == '0') {
break;
}
num = new BigDecimal(line);
}
t--;
System.out.println(sum.stripTrailingZeros().toPlainString());
}
}
}
``````

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 11821 - High-Precision Number

Change line

Code: Select all

``````while (input.ready()) {
It must be

Code: Select all

``while ( (line = input.readLine()) != null ) {``
Change line to

Code: Select all

``num = new BigDecimal(line.trim());``
If you have problems with Java post in Help on languages ‹ Java.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

RookiE3
New poster
Posts: 16
Joined: Tue Feb 18, 2014 7:59 pm

### Re: 11821 - High-Precision Number

I have changed the code as you said, but still WA

Please tell me if logic is OK or not.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11821 - High-Precision Number

Input:

Code: Select all

``````1
0.0
0
``````
Output should be 0
Check input and AC output for thousands of problems on uDebug!

mgavin2
New poster
Posts: 43
Joined: Sat Jul 28, 2012 6:29 pm

### Re: 11821 - High-Precision Number

idk what could be wrong with this supposedly easy problem.... something really stupid is catching me.

Code: Select all

``````thanks brianfry
``````
So here's my code while I go do something else. Thank you
Last edited by mgavin2 on Tue Oct 07, 2014 11:19 pm, edited 1 time in total.
all that matters is AC

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11821 - High-Precision Number

Input:

Code: Select all

``````1
0.01
0.09
0
``````
Output should be: 0.1
Check input and AC output for thousands of problems on uDebug!

mgavin2
New poster
Posts: 43
Joined: Sat Jul 28, 2012 6:29 pm

### Re: 11821 - High-Precision Number

omfg. Java BigDecimal method stripTrailingZeros only works some of the time (actually it seems to only work for zeros after the decimal point). Hence the stupidly looking use of compareTo.

Thank you brianfry
all that matters is AC

pointless0
New poster
Posts: 9
Joined: Wed Jan 13, 2016 3:24 am

### Re: 11821 - High-Precision Number

Interesting point of difference between my AC submission and uDebug...

Test input:

Code: Select all

``````1
0.00000000000007
0``````
My AC result:

Code: Select all

``0.00000000000007``
uDebug result:

Code: Select all

``7E-14``
Should I consider my solution unacceptable?

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 11821 - High-Precision Number

Problem descriprion says
All zeros after the decimal point located behind the last non-zero digit must be discarded
So your solution acceptable. uDebug gives same output as yours now.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman