Leading the way to the Future
 18 Oct 2009 12:58:08 pm by Newbie Does anyone know of an algorithm to grab the decimal part from division that could work with any language not using any built in commands other than straight arithmetic. ie: 7 /3 = 2.3333333 and it grab the .33333333
 Newbie wrote: not using any built in commands other than straight arithmetic.

That can be a challenge.

This seems tricky and I can't find/remember a way right now. I will be thinking on it. I am starting to doubt that exist a way...

Anyway this made me realize how to do a thing... Coding time!
Galandros wrote:
 Newbie wrote: other than straight arithmetic.

That can be a challenge.

This seems tricky and I can't find/remember a way right now. I will be thinking on it. I am starting to doubt that exist a way...

Anyway this made me realize how to do a thing... Coding time!

Thanks. Just so it doesn't sound confusing, I want it just using arithmetic. The way you quoted it, it seemed like I was asking for any way other than arithmetic. :biggrin:
 18 Oct 2009 01:55:19 pm by Builderboy2005 well, if you are using a language that can cast to an integer, that might be a good way. Like, 7.333 would be cast to 7, and then its simple subtraction to get what you need. It does depend on the language thigh, what are you using?
 18 Oct 2009 02:06:39 pm by Newbie PHP, but it would be nice to know something to just works across everything.
 18 Oct 2009 02:19:49 pm by bfr Yeah, I was thinking what Builderboy2005 said. I think nearly every programming language should have some sort of floor/cast to integer method built-in. If it for some reason doesn't and you can only add, subtract, multiply, and divide, then you could get your result by calculating 7 mod 3 using only those operations, which equals 1, and then 1/3 is your result.
 18 Oct 2009 03:39:52 pm by Weregoose Here's a funky way that probably wouldn't be very useful in your case: [font="times new roman"]1/2 – arctan(cot(π x))/π Theoretically, though, this only works for positive numbers that are not integer multiples of 1/2. But if you have access to int(), floor(), mod(), round(), etc., there are many transformations that will net you fpart().
 Weregoose wrote: Here's a funky way that probably wouldn't be very useful in your case: [font="times new roman"]1/2 – arctan(cot(π x))/π Theoretically, though, this only works for positive numbers that are not integer multiples of 1/2. But if you have access to int(), floor(), mod(), round(), etc., there are many transformations that will net you fpart().

haaaaa. :biggrin: Like you and many others said, I'm probably better off just using the built in functions. PHP has round and mod from what I know as well as others probably, but thanks for your help. Didn't realize it would be this complex. Well I guess I sorta did because of how long I was trying to figure out a way with no results.

Thanks everybody.
 18 Oct 2009 08:00:12 pm by GloryMXE7 well ypu could transform the fraction to a mixed number and take only the fraction part ex 7/3 = 2 1/3 1/3 = .333333 but your probably better of with the built in functions though
Going on Glory MXE7's post some pseudo code might be:

 Code: Repeat number<1 number-=1 End Loop Display number
 19 Oct 2009 11:26:26 am by Newbie Quick question off topic though: If I have a php page say: home.php and I want it to say home.php?page=1 how would I get ?page=1 in the url the first time some visits the page? It's easy to have a link that someone can click and it does that, but what can be done the first time someone comes to the page to change the URL to say that?
 20 Oct 2009 01:37:42 am by cjgone Redirect the page?
If home.php is equivalent to home.php?page=1, why does it matter which URL you use?

As to the original question: you're really just asking how to implement the modulus operation. One way:
 Code: a := 1 while x >= a or x <= -a:   a := a * 2 while a > 1:   a := a / 2   if x >= a then x := x - a   if x <= -a then x := x + a
 02 Mar 2011 06:35:48 pm by Lego don't know what php does if you write an float into an int, but in c you can do it like that int x; float y=7,33333; x=y; now x = 7 then just to y=y-x so you geht y=0,33333 Edit: Sorry i haven't read the posted date