Wrox Programmer Forums
|
BOOK: Beginning Java 2
This is the forum to discuss the Wrox book Beginning Java 2, SDK 1.4 Edition by Ivor Horton; ISBN: 9780764543654
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 28th, 2004, 03:48 AM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default math.floor

hello guy. i have a problem with ceiling and Floor method..i know that
Math.ceil(7.5) is == 8

but how can i do to Math.ceil (75) to become 80
or
 Math.ceil(125) to become 130...???

also to Math.floor(25) to become 20

ok guys! i will be waiting for ur reply!. bye


 
Old October 29th, 2004, 11:24 AM
Authorized User
 
Join Date: Sep 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Watch this: you can chop-off with (int) too!

Quote:
quote:Originally posted by casper


how can I get Math.ceil (75) to become 80
or Math.ceil(125) to become 130...???
int theNumber = 10* (int)Math.ceil(oldNumber/10.0); // all data types

Quote:
quote:
also to Math.floor(25) to become 20
int theNumber = 10* (int)(oldNumber/10.0); // all data types


// You might combine these in a method like:
public static double roundNumber(double number, int digits, boolean roundUp)
{
double factor = Math.pow(10.0, digits); // digits=1, factor=10

if(roundUp)
    return factor*(int)Math.ceil(number/factor);

return factor*(int)(number/factor); // else
}
// I didn't try this out, but it should work!


Cheerz!
Franz





Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help with Math.pow trryan5 Java Basics 4 July 27th, 2007 06:12 AM
Math question dparsons ASP.NET 1.0 and 1.1 Professional 5 June 14th, 2006 02:31 PM
Math Namespace transtar C# 3 February 12th, 2006 09:50 AM
Math functions-Please help! jroxit ASP.NET 2.0 Basics 5 December 28th, 2005 12:21 PM
York Math -- regarding... vijayk Wrox Book Feedback 0 February 5th, 2005 06:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.