How to remove the decimal point

0

I have this method

   public void calcularVotosTotal(){

    System.out.println("votos valiudos " + this.getNumeroEleitores() * 0.8 + "% " + " Votos Brancos "
                        + this.getNumeroEleitores() * 0.06 + "% " + " votos nulos "
                        +this.getNumeroEleitores() * 0.14 + "% ");
}

I have here the main method

 public static void main(String[] args) {
    AlgoritimoNumeroTotalPessoas antp = new AlgoritimoNumeroTotalPessoas(100);
    antp.totalEleitores();
    antp.calcularVotosTotal();
}

And here is the output of the console below, how do I remove the points in the decimal? and leave the output so 80%, 6%, 14%

Numero total de eleitores 100
votos validos 80.0%  Votos Brancos 6.0%  votos nulos 14.000000000000002% 
    
asked by anonymous 29.10.2016 / 20:25

2 answers

0

It was true that I was doing the cast the wrong way, obg all!

public void calcularVotosTotal(){

    System.out.println( "votos validos "  + (int)(this.getNumeroEleitores() *  0.8) + "% " + " Votos Brancos "
                        + (int)(this.getNumeroEleitores() * 0.06) + "% " + " votos nulos "
                        + (int)(this.getNumeroEleitores() *  0.14) + "% ");
}
    
30.10.2016 / 01:49
1

From what I saw, you want to return an integer value, I think the "problem" is in the return of the getNumeroEleitores method, which should actually be long , I guess you're returned a double or float , in this case you only have to convert to long , here is an example below:

public class HelloWorld{
     public static void main(String []args){
        double d = 15.5;
        System.out.println((long) d); //saida: 15
     }
}

Note: I have used long for fear of bursting the maximum value of int .

    
29.10.2016 / 22:52