Visualizzazione dei risultati da 1 a 8 su 8
  1. #1

    [Java] Rappresentare prezzi x,00

    Ciao,
    ho una jTable in cui ci sono dei valori numerici decimali che rappresentano dei prezzi.

    Come faccio a forzare la visualizzazione di tali valori nella forma y,xx a prescindere dal valore assunto dai decimali (y,00 o y,10 ecc)?


  2. #2

  3. #3
    Perfetto... ecco cosa sono riuscito a produrre:

    codice:
    Double number = new Double(12.2575);
        System.out.println("Prima: "+number);
    
        DecimalFormat numberFormatter = new DecimalFormat();
        numberFormatter.setDecimalFormatSymbols(new DecimalFormatSymbols());
        numberFormatter.setDecimalSeparatorAlwaysShown(true);
        numberFormatter.setMaximumFractionDigits(2);
        numberFormatter.setMinimumFractionDigits(2);
    
        System.out.println("Dopo: "+numberFormatter.format(number));

  4. #4
    Altro problemone!

    Come si fa a far sparire il separatore delle migliaia?

    Per intenderci, al posto di avere 1.000,00 vorrei avere 1000,00..


  5. #5
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    usa questo al posto dei metodi che hai messo tu
    numberFormatter = new DecimalFormat("#.##"); se vuoi ,12
    numberFormatter = new DecimalFormat("0.##"); se vuoi 0,12

  6. #6
    Cosė non funziona nella JTable:
    codice:
    java.text.DecimalFormat numberFormatter = new java.text.DecimalFormat("0.##");
    Invece cosė va alla grande:
    codice:
    java.text.DecimalFormat numberFormatter = new java.text.DecimalFormat("0.");
    numberFormatter.setMaximumFractionDigits(2);
    numberFormatter.setMinimumFractionDigits(2);
    Misteri..

    Comunque grazie mille!

  7. #7
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    ho scritto una stupidata
    new DecimalFormat("0.00") o new DecimalFormat("#.00")

  8. #8

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.