[ https://issues.apache.org/jira/browse/GROOVY-7652?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
John Wagenleitner updated GROOVY-7652: -------------------------------------- Description: The {{trunc}} methods on Float/Double use the {{Math.floor}} method for all values, however for negative values this causing rounding. I think for negative values {{Math.ceil}} needs to be used. Here are some asserts to show the rounding: {code} Float f = -123.739f Double d = -123.739d assert -123f == f.trunc() // fails: -124 assert -123d == d.trunc() // fails: -124 assert -123.73f == f.trunc(2) // fails: -123.74 assert -123.73d == d.trunc(2) // fails: -123.73 {code} was: The {{trunc}} methods on Float/Double use the {{Math.floor}} method for all values, however for negative values this causing rounding down. I think for negative values {{Math.ceil}} needs to be used. Here are some asserts to show the rounding: {code} Float f = -123.739f Double d = -123.739d assert -123f == f.trunc() // fails: -124 assert -123d == d.trunc() // fails: -124 assert -123.73f == f.trunc(2) // fails: -123.74 assert -123.73d == d.trunc(2) // fails: -123.73 {code} Summary: Float/Double trunc methods perform rounding for negative values (was: Float/Double trunc methods round down for negative values) > Float/Double trunc methods perform rounding for negative values > --------------------------------------------------------------- > > Key: GROOVY-7652 > URL: https://issues.apache.org/jira/browse/GROOVY-7652 > Project: Groovy > Issue Type: Bug > Components: groovy-jdk > Affects Versions: 2.4.5 > Reporter: John Wagenleitner > Priority: Minor > > The {{trunc}} methods on Float/Double use the {{Math.floor}} method for all > values, however for negative values this causing rounding. I think for > negative values {{Math.ceil}} needs to be used. > Here are some asserts to show the rounding: > {code} > Float f = -123.739f > Double d = -123.739d > assert -123f == f.trunc() // fails: -124 > assert -123d == d.trunc() // fails: -124 > assert -123.73f == f.trunc(2) // fails: -123.74 > assert -123.73d == d.trunc(2) // fails: > -123.73 > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)