How to reject a fractional part

How to reject a fractional part

In practical calculations it is necessary to deal with integers less often - most often it is the fractional values which are written down in a format of decimal or common fractions. At the excess number of fractional categories they are rounded, as a rule, but in certain cases there is a need just to reject all fractional component. It is very easy to make it.

Instruction

1. If a fractional part of the number which is written down in a format of decimal fraction needs to be "rejected", then just write down all its categories to a decimal comma, and her and all categories are more right - remove. If you needed not to reject a fractional part, and to round to the whole value, then it would be necessary to work likewise if after a decimal comma there was one of figures with 0 on 4. In other cases to the received result it is advisable to add unit. For example, having rejected fractional Part 747.75, you have to receive 747, and having rounded this number - 748.

2. Similarly arrive and with the number which is written down in a format of the common mixed fraction - leave only its whole part, and do not write the fraction standing after a gap. If it was talked of rounding operation, then this rule would remain in case the numerator of a fractional part is less than a half of a denominator, and otherwise to an integer it is necessary to add unit. For example, from fraction has to remain 41 8/15 after rejection of a fractional part only 41, and when rounding - 42.

3. If the initial number is written down in a format of the improper common fraction, then it is necessary to make some calculations for rejection of a fractional part. Divide without the rest numerator into a denominator - received private and will be result of transformation, and about a remainder of division forget. If you applied operation of rounding to this numerical format, it should carry out division to within the 100-th - if the first figure after a comma is more four, it would be necessary to add unit to the whole part. For example, rejection of fractional Part 53/15 will give number 3, and rounding - 4.

4. If there is a need to get rid of a fractional part in any program, then it is necessary to use available tools in a concrete programming language. For example, in the PHP language there is a built-in sprintf function, having transferred which a reference value, and as type of data having specified integer values (u), you receive necessary "trimming" instead of rounding: echo sprintf ("" %u"", '747.75') Performance of this line will reject a fractional part in initial number 747.75 and will bring 747.

5. The same result in the PHP language can be received with use of the built-in explode function - it creates the massif of values from a line variable, breaking it on the set dividers. Give to this function a point as a divider and a reference value, and then appropriate to a variable the first element of the massif created by function - it will contain all signs of initial number, excepting a fractional part. For example: $result = explode ('.', '747.75'); $result = $result [0];

6. If it was necessary to round value in the PHP language, but not to reject a fractional part, then you should use the built-in round function, transferring it the only variable - initial number: echo round(747.75);

Author: «MirrorInfo» Dream Team


Print