AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Arrotondare

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian)
View previous topic :: View next topic  
Author Message
Robby
Guest





PostPosted: Mon Dec 29, 2003 2:45 pm    Post subject: Arrotondare Reply with quote



C'è un metodo che arrotondi una numero e dia la possibilità di farlo x
eccesso o per difetto?
O anche solo x eccesso


Back to top
gnazio
Guest





PostPosted: Mon Dec 29, 2003 3:10 pm    Post subject: Re: Arrotondare Reply with quote



Robby <slop (AT) tin (DOT) it> ha scritto:

Quote:
C'è un metodo che arrotondi una numero e dia la possibilità di farlo x
eccesso o per difetto?

Dai un'occhiata alla classe
java.text.DecimalFormat

Quote:
O anche solo x eccesso

Di la verità! Sei un commerciante e ti stai facendo un programmino per gli
importi in euro! ;-)



Inviato da www.mynewsgate.net

Back to top
gnazio
Guest





PostPosted: Mon Dec 29, 2003 3:13 pm    Post subject: Re: Arrotondare Reply with quote



Scusa la castroneria, intendevo

java.math.BigDecimal


Inviato da www.mynewsgate.net
Back to top
Buff
Guest





PostPosted: Mon Dec 29, 2003 4:12 pm    Post subject: Re: Arrotondare Reply with quote

il matodo statico Math.round(x); ti permette di arrotandare secondo le
convenzioni corrette. Attenzione: i metodi di classe Math restituiscono
double dunque per ottenere degli int fai così:
double d = 1.25;
int i = (int)Math.round(d); //ottieni i = 1

I seguenti suggerimenti sono validi per numeri positivi (per i negativi
basta che ci pensi un attimo...)
Se vuoi arrotondare per difetto in ogni caso, bsta che fai un cast ad int
del dpuble in questione:
double d = 1.25;
int i = (int)d; //ottieni i = 1

Se vuoi arrotondare per eccesso in ogni caso basta che fai così:
double d = 1.25;
int i = (int)d + 1; //ottieni i = 2

Se vuoi devidere prima che arrotondamento fare introduci un if/else,
semplicemente.

Ciao Alberto.
"Robby" <slop (AT) tin (DOT) it> ha scritto nel messaggio
news:k6XHb.21417$_P.954501 (AT) news4 (DOT) tin.it...
Quote:
C'è un metodo che arrotondi una numero e dia la possibilità di farlo x
eccesso o per difetto?
O anche solo x eccesso





Back to top
Robby
Guest





PostPosted: Tue Dec 30, 2003 12:07 pm    Post subject: Re: Arrotondare Reply with quote


Quote:
Di la verità! Sei un commerciante e ti stai facendo un programmino per gli
importi in euro! Wink

Eheh!! no! magari!!
stavo solo facendo un menù x scegliere una pagina, solo che x avere il
totale delle pagine devo arrotondare x eccesso!



Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.