Why is it important to you to have a float? Once you've truncated it, you have a rational number, by definition. Are you sure you want to truncate the number, rather than performing the truncation in the presentation layer?
On Wed, Jul 23, 2008 at 10:34 AM, cdrick cdrick65@gmail.com wrote:
Float has a truncate and round off protocal with metods that truncate and round to integer.
So it looks you have to do something like
(aFloat * (10^desiredDecimals) + 0.5) truncated / (10^desiredDecimals)
or without the + 0.5 for truncation.
close to what I proposed earlier ;-) Just need a conversion to Float as it returns a fraction.
so no existing method... Isn't it something common ? _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Why is it important to you to have a float? Once you've truncated it, you have a rational number, by definition. Are you sure you want to truncate the number, rather than performing the truncation in the presentation layer?
In my case, this is only for presentation. The real float doesn't change. And anyway rounded and truncated doesn't change the number value as they are immutable.
a := 3.4456. a rounded. a "-> 3.4456"
You meant maybe I use ScaledDecimal instead of Float?
Hello Cédrick,
search the "truncating and rounding" and "printing" protocols of Number there you'll find some help.
arffff thanks all ;)
1.23456 printShowingDecimalPlaces: 3
I knew that had to exist...Since I know the method finder I became lazy to search far ;)
See you
Cédrick
2008/7/23 Herbert König herbertkoenig@gmx.net:
Hello Cédrick,
search the "truncating and rounding" and "printing" protocols of Number there you'll find some help.
-- Cheers,
Herbert
Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Hello Marcin,
agreed with the the beginning of your post.
Floats (their finite precision representation) often create as many problems as they solve, if it weren't for trigonometric functions I'd try to keep away from them as far as I could :-))
MT> Are you sure you want to truncate the number, rather than MT> performing the truncation in the presentation layer?
And then Cédrick will go searching the printing protocol of float and find the same problem in a different disguise.
Float's private protocol might contain a start with absPrint.....
Cheers,
Herbert
beginners@lists.squeakfoundation.org