[Solved-1 Solution] Pig round down to the nth decimal place ?
Problem:
f(3.999999, 1) = 3.9
f(3.42317, 2) = 3.42
f(1.03, 1) = 1.0
How to round a float or double down to the nth decimal place in pig ?
Solution 1:
- PIG has
ROUND_TO. That will do the rounding based on the decimal points needed.
B = FOREACH A GENERATE ROUND_TO(input,num_of_decimal_places);
Example:
Input file:
3.999999
3.42317
1.03
A = LOAD 'file' as (num:float); B = FOREACH A GENERATE ROUND_TO(num,2); dump B;
Output:
(4.0)
(3.42)
(1.03)