# Algorithm for calculating floating point numbers in Batch | By kvc

Hey hello Guys, Today I'm Gonna share one of my best batch programming work, as we have created an proper algorithm for calculating Floating point numbers from pure Integer environment. In other words, we may have found the way of windows to define floating point integers in the computer programming. This algorithm is fully created by kvc, and not even a single info about floating point values is taken from any other source… So, without wasting any time, let's talk about the Algorithm.

### The algorithm is divided into 3 parts:

- For Plus (+) and (-) operations,
- For Multiplication (x) operations,
- For Division (/) operations.

Now, In general we have to take some assumptions in order to create something, the same case is here, as we have assumed some facts before making this awesome algorithm. We were working on this project, and while having our copy and pen on desk. we thought of the following basic fact.

#### 'As we know that every float value has two parts.'

- The Part Before 'dot' (.)
- The Part After 'dot' (.)

Example |

## Considering Cases:

- If we want to
**add two floating point values**then…**e.g.**2.36 + 3.649 = 6.009We can add**Part 1**&**Part 2**of both numbers separately but to do so, we have to make**Part 2**of Both numbers in same decimal places. Like we can’t just simply add 36 to 649, it will mess-up with our result… We have to make 36 Ã 360 first (so that decimal places becomes same…**i.e.**3 digits after dot ‘.’) then we can add**Part 2**of both numbers… and adding**Part 1**of both the numbers will be easier enough…

Similar operations are valid for subtracting floating point numbers. The Negative sign will be handled via two '**If**' statements in the code. - And Algorithm for
**multiplying two floating point**numbers is very easier than all others… As we just have to count the total no. of digits after dot ‘.’ in both the Numbers…**i.e.**In above case,**Number 1**(2.39) has 2 digits after dot ‘.’ And**Number 2**(3.649) has 3 digits after dot ‘.’, hence the total number of digits after dot is 5…Now simply multiply 239 & 3649 and Place a Dot ‘.’ Leaving last 5 digits of answer.**e.g.**2.36 * 3.649 = 8.61164 - And the algorithm for
**dividing the two floating point numbers**is somewhat a mixture of the above two algorithms…**i.e.**first we have to make the decimal places of numbers same… (same as in 1st algorithm) and then we can count the total number of the digits after dot and then perform simple division operation… The only change in this algorithm is that we have to multiply the number firstly with a multiplier which is**10000**of any other multiple of**10**so that on division, we don’t lose any part of result and we place dot leaving same number of digits of result as ‘**zeros**’ in the multiplier.

Try to understand above paragraph with following example…

Division Algorithm Explained |

So, finally this Amazing Post ends… and if in case you didn't get anything from the above explanation or like my work about Batch Programming, then please leave me a comment down this post… or you can also mail me at

**karanveerchouhan@gmail.com.**Just do leave comment or An E-mail, even if you don’t like the way I represent things and if you have any suggestion… then you’re most welcome… And if this trick helps you in any of your work… feel free to say thanks to me… ’cuz you’ll not loose anything by saying Thanks…
Keep learning, keep sharing…

Be happy, spread happiness…

Download Document File : Floating Point Algorithm.docx

#TheBATeam

## No comments: