for any type of rounding scheme and any reasonable number of
>> digits.
>>
>> -Nando(Canada)
>>
>>
>> --
>> Open WebMail Project (http://openwebmail.org)
>>
>>
>> -- Original Message -------
>> From: Gianluigi <bagone...@gmai
pen WebMail Project (http://openwebmail.org)
>
>
> -- Original Message ---
> From: Gianluigi <bagone...@gmail.com>
> To: mailing list for gambas users <gambas-user@lists.sourceforge.net>
> Sent: Thu, 13 Jul 2017 12:30:23 +0200
> Subject: Re: [Gambas-user] B
Project (http://openwebmail.org)
-- Original Message ---
From: Gianluigi <bagone...@gmail.com>
To: mailing list for gambas users <gambas-user@lists.sourceforge.net>
Sent: Thu, 13 Jul 2017 12:30:23 +0200
Subject: Re: [Gambas-user] Best ways to format float values
> One t
Great Tobias,
You are a good teacher and I am honored to have your attention.
OK I understand, never more extravagant mathematics.
Thank you very much for your explanations
Regards
Gianluigi
P.S. You will not believe it but some tests with Floor and Ceil I did :-(
2017-07-13 20:00 GMT+02:00
On Thu, 13 Jul 2017, Gianluigi wrote:
> I would not be misunderstood.
> I had understood that Alex wanted a forced increase "Round".
>
> To recap:
>
> Dim n As Float = 26.66016
> Dim b As Byte
>
> Print Int(n * 100) / 100 ' Normal truncate, as already
> mentioned by
I would not be misunderstood.
I had understood that Alex wanted a forced increase "Round".
To recap:
Dim n As Float = 26.66016
Dim b As Byte
Print Int(n * 100) / 100 ' Normal truncate, as already
mentioned by other
Print Round(n, -2)' Normal
2017-07-13 1:46 GMT-04:00 bb :
> I always round i.e. Print Round(26.66016,-2) -->
the digits see -> .660
> which is 26.66 by the way, not 26.67! (I have no idea how you got that.)
due 660 and -2 said the firts two digits, the round will take effect only
in last
Also consider: -
Public Sub Main()
Dim fNum As Float[] = [26.66016, 26.66516] 'Note 26.660..
and 26.665..
Dim fTemp As Float
For Each fTemp In fNum
fTemp *= 100
fTemp += 0.5
fTemp = Int(fTemp)
fTemp /= 100
Print fTemp;;
Next
'Output 26.66 26.67
End
-
Check
One thing that could be useful?
Public Sub Main()
Dim n As Float = 26.66016
Dim b As Byte
b = Val(Mid(CStr(Frac(n)), 5, 1))
Print Round(n, -2)
If b >= 5 Then
Print Round(n, -2)
Else
Print Round(n + 0.01, -2)
Endif
End
Regards
Gianluigi
2017-07-13 7:39 GMT+02:00
alexchernoff wrote
> Peace to all,
>
> this might a bit silly but what is the best way to format float values
> like 26.66016 into having two digits AND/OR with rounding them?
>
> e.g.
> 26.66016 becomes 26.66 shortened
> 26.66016 becomes 26.67 rounded
>
> cheers!
You
I can say this is the best way to do what you want, but I use the following:
* Print Int(100.55 * 100) / 100.00 Print Round(100.55, -2)*
The first operation truncates the number to 100.55 (no rounding takes
effect).
The second operation rounds the number to at most two digits after
I always round i.e. Print Round(26.66016,-2) --> which is 26.66
by the way, not 26.67! (I have no idea how you got that.)
b
On 13/07/17 15:09, alexchernoff wrote:
Peace to all,
this might a bit silly but what is the best way to format float values like
26.66016 into having
Peace to all,
this might a bit silly but what is the best way to format float values like
26.66016 into having two digits AND/OR with rounding them?
e.g.
26.66016 becomes 26.66 shortened
26.66016 becomes 26.67 rounded
cheers!
--
View this message in context:
13 matches
Mail list logo