Appear 1.0k instead of number 1000 and so on

1

How can I make it appear instead of 1000 to appear 1.0k, and so on?

1000 - 1,0k
2000 - 2,0k
10000 - 10,0k
100000 - 100,0k

and etc ...

@Override
    public double getValor(String arg0) {
        Pessoa pessoa = Main.getPessoa();
        double valor = base.configvalor.getConfig().getConfigurationSection(pessoa.getNome()).getDouble("Valor");
        if (base.configvalor.getConfig().getConfigurationSection(pessoa.getNome()).getDouble("Valor") >= 1000) {
            double resultado = Math.ceil(valor/1000.0);
            return (resultado);
        }else {
            return valor;
        }
    }
    
asked by anonymous 29.11.2017 / 23:36

1 answer

2
public class Main {

  public static void main(String args[]) {
    System.out.println(abreviarComK(1000));
    System.out.println(abreviarComK(2000));
    System.out.println(abreviarComK(10000));
    System.out.println(abreviarComK(300));

  }


  public static String abreviarComK(long numero) {

    if (numero < 1000) {
      return Long.toString(numero);
    } else {
      return (numero/1000.0 + "k").replace(".", ",");
    }

  }

}

You do not need to replace if you are going to use a dot instead of a comma.

See working at IdeOne .

    
30.11.2017 / 00:09