Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | "Dr.UgoGagliardelli" <do.not.spam@me.please> |
| Newsgroups | it.comp.java |
| Subject | Re: sommare valori da JTextField |
| Date | Tue, 29 Sep 2015 12:22:43 +0200 |
| Organization | Aioe.org NNTP Server |
| Lines | 43 |
| Message-ID | <mudopd$g6t$1@speranza.aioe.org> (permalink) |
| References | <mudfum$q7v$1@speranza.aioe.org> |
| NNTP-Posting-Host | klfP30DkLjAo5fAX8way8g.user.speranza.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=iso-8859-15; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | csiph.com it.comp.java:8560 |
Show key headers only | View raw
Il 29.09.2015 09.48, Gulp® ha scritto:
> C'è qualcosa di sbagliato in questo codice?
>
> private void Somma(){
> double sum =0;
> double imp=0;
> String num;
> for (int i=0;i<13;i++){
> num=txtImportoriga[i].getText();
> if (num.length()>0){
> //imp=Double.valueOf(num);
> imp=parseDouble(num);
> }
> else{
> imp=0;
> }
> sum=sum + imp;
> txtTotale.setText(Uty.StrFormattaCur(sum,false));
> }
> }
>
> Alcuni txtImportoriga hanno stringa: ""
>
imp=parseDouble(num);
Cosa fa'?
A mio parere dovrebbe:
double parseDouble(String num) {
if (num == null || num.trim().isEmpty())
return 0d;
double val = 0d;
try {
val = Double.parseDouble(num.trim());
catch(Excepion e) {}
return val
}
e sostituire da 'for (int i=0;i<13;i++){' fino a 'sum=sum + imp;' con:
sum += parseDouble(num);
Comunque ti segnalo la classe JFormattedTextField che dipendentemente da
come viene inizializzata, tramite il betodo getValue potrebbe restituire
solo i tipi corretti.
Back to it.comp.java | Previous | Next — Previous in thread | Next in thread | Find similar
sommare valori da JTextField Gulp® <gulp@hotmail.it> - 2015-09-29 09:48 +0200
Re: sommare valori da JTextField "Dr.UgoGagliardelli" <do.not.spam@me.please> - 2015-09-29 12:22 +0200
Re: sommare valori da JTextField Gulp® <gulp@hotmail.it> - 2015-09-29 15:12 +0200
csiph-web