File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes how to find out the multiples of 12? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to find out the multiples of 12?" Watch "how to find out the multiples of 12?" New topic
Author

how to find out the multiples of 12?

senthil sen
Ranch Hand

Joined: Oct 10, 2002
Posts: 184
say a user enter a value ---
that value is lesser than multiples of 12 then it should be rounded to that multiple of 12
eg-
user value --- 22
multiple valueof 12 --24

the user value should be rounded to 24
if user value entered is ---35
multiple value of 12 --- 36
the user value should be rounded to 36
how can i do this??
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
To round up: ((value+11)/12)*12
Proper rounding: ((value+6)/12)*12
To round down: (value/12)*12
- Peter
Greg Brouelette
Ranch Hand

Joined: Jan 23, 2002
Posts: 144
Don't forget the modulus operator %
int x = 15;
int y = x%12;
y will be the remainder of 15/12 In this case "3". If y is 0 then it is divisible by 12. Other wise you know how far away you are from a multiple of 12 and can round up or down as required.


For a good Prime, call:<br />29819592777931214269172453467810429868925511217482600306406141434158089
senthil sen
Ranch Hand

Joined: Oct 10, 2002
Posts: 184
thanks guys for ur reply,well it works if there is an input below 12
what if the user selects 19
i should be able to check it out and find if its is near to a multiple to 12
eg; 19 is near to 24
29 is near 24
31 is near 36
40 is near 36
44 is near 48

how to check these options??
this all happens when a user selects from the user input?
say a user wanna buy apples...he selects these..
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Peter gave you this formula: ((value+6)/12)*12 try putting your numbers (value) in that. Do not forget that "/" is integer division (without remainder).
[ February 21, 2003: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to find out the multiples of 12?