You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pig.apache.org by "Cheolsoo Park (JIRA)" <ji...@apache.org> on 2014/05/10 23:56:19 UTC
[jira] [Commented] (PIG-3926) ROUND_TO function: rounds
double/float to fixed number of decimal places
[ https://issues.apache.org/jira/browse/PIG-3926?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13993668#comment-13993668 ]
Cheolsoo Park commented on PIG-3926:
------------------------------------
+1. I'll commit it shortly.
> ROUND_TO function: rounds double/float to fixed number of decimal places
> ------------------------------------------------------------------------
>
> Key: PIG-3926
> URL: https://issues.apache.org/jira/browse/PIG-3926
> Project: Pig
> Issue Type: New Feature
> Affects Versions: 0.12.0
> Reporter: Philip (flip) Kromer
> Assignee: Philip (flip) Kromer
> Priority: Minor
> Labels: builtin, function, math
> Fix For: 0.13.0
>
> Attachments: 0001-Unit-tests-for-ROUND.patch, 0002-ROUND_TO-UDF-safely-rounds-values-to-given-precision.patch
>
>
> The too-often used trick of rounding to a fixed number of decimal places by writing '1000 * Math.round(num / 1000.0)' is not only unsightly, it's numerically imprecise (http://stackoverflow.com/a/12684082/41857). The attached patch adds a function to do this.
> ROUND_TO(val, digits) accepts a single float or double value, along with an integer number of digits, and returns the value to that number of decimal places
> Examples:
> {code}
> ROUND_TO(3.14159f, 3) -- returns a float 3.142
> ROUND_TO(3.14159d, 0) -- returns a double 3.0.
> {code}
> I also added unit tests for ROUND -- there were none before that I could find.
> I don't know how to write a unit test that the schema correctly routes to FloatRoundTo and DoubleRoundTo -- if the ones I provided are insufficient please point me to a simple example to emulate.
--
This message was sent by Atlassian JIRA
(v6.2#6252)