Italian Arrotondare un risultato

micro

Well-Known Member
Licensed User
Longtime User
Salve ragazzi,,
solitamente non mi sono mai preoccupato di dover inserire nei codici operazioni matematiche particolari perchè non si presentava mai la necessità ora però ho un piccolo quesito da porVi.
Come posso arrotondare un certo risultato a dei valori predefiniti e cioè a 0,5 a 2 a 5 a 10 ecc. ?
In pratica:
123,2 = 123,0 (arrotondamento a 0,5)
123,3 = 123,5 (arrotondamento a 0,5)
121 = 122 (arrotondamento a 2)
123 = 124 (arrotondamento a 2)
122 = 120 (arrotondamento a 5)
123 = 125 (arrotondamento a 5)
123 = 120 (arrotondamento a 10)
126 = 130 (arrotondamento a 10)
ecc.

C'è un modo rapido per ottenerlo?

Grazie mille
 

giannimaione

Well-Known Member
Licensed User
Longtime User
Ciao Micro,
sara' questa giornata, sara' il vento di scirocco, ma non ho capito il tuo problema
In pratica:
123,2 = 123,0 (arrotondamento a 0,5)
123,3 = 123,5 (arrotondamento a 0,5)
121 = 122 (arrotondamento a 2)
123 = 124 (arrotondamento a 2)
122 = 120 (arrotondamento a 5)
123 = 125 (arrotondamento a 5)
123 = 120 (arrotondamento a 10)
126 = 130 (arrotondamento a 10)
cosa intendi per arrotondamento a 0,5 - 2 - 5 -10 ???
perche' 123,2 diventa 123,0 mentre 123,3 diventa 123,5 ??? (arr=0,5)
e poi:
(arr=5) 122=120 e 123=125 ????
ho capito solo che i valori arrotondati sono divisibili (non hanno resto) per l'arrotondamento, ma poi null'altro
:confused:

un saluto,
 

micro

Well-Known Member
Licensed User
Longtime User
ok :),
allora per arrotondamento a 0,5 significa che il risultato deve avere dei step a 0,5.
In pratica:
0,5
1,0
1,5
2,0 ecc.
Con arrotondamento a 10 avremo:
10
20
30 ecc.

Probabilmente ho usato impropriamente la parola arrotondamento, adesso spero di essere stato più chiaro :signOops:
 

klaus

Expert
Licensed User
Longtime User
You should use the formula below:
B4X:
[SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New]RoundedValue=[/FONT][/SIZE][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](Value/RoundAt+[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0.5[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])*RoundAt[/SIZE][/FONT][/SIZE][/FONT]

I joined a small program to test it.

Sorry for answering in english, but I don't speak italian.

Best regards
 

Attachments

  • Round.sbp
    736 bytes · Views: 228

giannimaione

Well-Known Member
Licensed User
Longtime User
Ciao Micro,

Klaus mi ha preceduto :)

sì la formula è la seguente
Risultato=Int(Valore/FattorediArrotondamento+0.5)*FattorediArrotondamento

quindi come vedi abbiamo trovato la stessa formula.

A presto,
 

klaus

Expert
Licensed User
Longtime User
Hi Gianni,

The only difference between your formula and mine is that yours is in Italian and mine in English.
But fortunately, from the mathematical point of view those are the same :).

Best regards.

Google traduzione

L'unica differenza tra la vostra e la mia formula è che il vostro è in italiano e in inglese miniera.
Ma per fortuna, dal matematico punto di vista quelli sono gli stessi :).​

Ciao.
 

giannimaione

Well-Known Member
Licensed User
Longtime User
+-*/

Hi Klaus,

you are right +-*/ is universal language :)
 

micro

Well-Known Member
Licensed User
Longtime User
Grazie ad entrambi,
adesso che ho visto la formula mi si è rinfrescata la mente..... lo sapete che con l'età tutto tende a degradarsi (speriamo non tutto ....: ehehehe).

Bye ;)
 

giannimaione

Well-Known Member
Licensed User
Longtime User
nel blu dipinto di blu

non preoccuparti Micro, in fondo c'e' semre la pillola blu eheheheh:)
 

AmsConsulting

New Member
Licensed User
Longtime User
Come posso arrotondare il numero 38.925.Sia Round2 che NumberFormat2 mi ritornano 38.92 invece di 38.93. Come posso fare l'arrotondamento commerciale?
 
Last edited:

sirjo66

Well-Known Member
Licensed User
Longtime User
Lui sta parlando di arrotondamento commerciale, quindi il 5 lo deve arrotondare sopra, mentre il 4 lo deve arrotondare sotto, per cui credo che il mio +0.001 sia giusto.
Se si trova con un 38.925 e fa +0.001 si trova con 38.926 che viene arrotoandato a 38.93 (come voleva lui), mentre se si trova con 38.924 e fa +0.001 si trova con 38.925 che arrotanda (giustamente) a 38.92

(almeno io ho capito così, ecco il perchè del mio +0.001)

Sergio
 
Top