Maths Question?

Hey guys

Having a little bit of a math problem, i need a way in blue prints to take a number say 19 split that number in to 2 numbers of 10 and 9, but the number 19 could be anything 28, 20, 87 any thing so how can i make sure when i split the numbers up is does it by as close to half as possible without getting decimal points or remainders?

i know this is a bit of an odd question so if anyone needs anymore details please ask

thanks guys :slight_smile:

i recently used something which may help you : “fraction” :
calc number /2 then branch : fraction = 0 True : number/2 x 2. False : (number+1) / 2 and (number - (number+1) / 2)

(i haven’t find a way to check if a number is peer or not…)

Just use the remainder to give you the other number. Basically, assuming you have 19, you would divide 19 by 2.0, giving you 9 and a remainder of 1. Then you just add the result and the remainder and you get 10 (you can call ToInt to get the value as a whole number). You can wrap that into a function easily.

Thanks for the reply so how would i get a remainder of 1 as if you divide 19 by 2 then i would get 9.5? is there a node for this sort of equation?

Ok Never mind i found a node called Division (Whole and Remainder) that works thanks for your help :slight_smile:

I didn’t know this function : this is “division”. Thanks for new info RPotter ^^

This would be the easiest way to accomplish this (see attached image) :slight_smile:

EDIT: looks like you found it already, I’ll leave this here in case someone needs it in the future.

yeah thanks mate really helped me but just hit a snag if i divide a number under 1 e.g 0.7 divided by 2 i get a 0 remainder and return value, i understand why that this is for whole numbers but now im looking for something for less then whole e.g. 0.7 divided 2 = remainder 0.1 and return value of 0.3 is there a way of still using this node with some equations before and after to still get this affect thanks for all the help :slight_smile:

What exactly do you want in this case? Do you only want it for a certain level of fraction? For example, tenths (0.0-0.9), hundreths (0.01-0.09), etc? If so, you can just multiply the input value by, say 10 for tenths (100 for hundreths), then do it as usual, then divide the resulting values by the same number.

I have tried to do that kind of setup but for some reason the value after the divide is 0 and im not sure why?

Also Tried this but i still get 0

The Problem seams to be that i can not divide the return value of the Divide (Whole and Remainder) node at all even if i set a variable from it and im not sure why?

The return value is an Integer. You need to convert it to a float and divide by 10.0. If you divide 7 as an integer by 10, you’ll get 0; if you divide 7.0 by 10.0, you’ll get 0.7.

In this context, the remainder only exists for integer division. When you divide fractions, you don’t get a remainder and 0.7 represents the fraction 7/10ths. You need to scale things up to whole numbers to be able to use this splitting method. If you only ever are dealing with one decimal place, you can just multiply your numbers by ten before hand and then divide afterwards. You’ll want to check for a decimal place before doing the multiplication, however, since that will break your calculations for whole numbers.

0.7 * 10 = 7
7 / 2 = 3 (rounded down)
7 % 2 = 1 (modulus)
numbers are 3 and 4 (3 + 1)
3/10 = 0.3
4/10 = 0.4

thanks every one i managed to get it working once i put it in a function of its own some how that fixed the problem, thanks guys