Bug 387540 - Precision loss when converting certain units
Summary: Precision loss when converting certain units
Status: RESOLVED FIXED
Alias: None
Product: UOMo
Classification: Technology
Component: Units (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Werner Keil CLA
QA Contact:
URL: http://www.eclipse.org/forums/index.p...
Whiteboard:
Keywords: example
Depends on:
Blocks:
 
Reported: 2012-08-18 14:59 EDT by Werner Keil CLA
Modified: 2012-08-18 15:26 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Werner Keil CLA 2012-08-18 14:59:25 EDT
Conversions between METRE and KILOMETRE end up with a RationalConverter where a MultiplyConverter would be more appropriate.

See forum entry. Either RationalConverter needs improvement when handling BigDecimal values, or a MultiplyConverter (for Double/BigDecimal type floating values) should be used.
Comment 1 Werner Keil CLA 2012-08-18 15:03:12 EDT
Test snippet to reproduce, will go into test case or example code:
---
LengthAmount x = new LengthAmount(1.0001, SI.Prefix.KILO(SI.METRE));
IMeasure<Length> xi = x.to(SI.METRE);
System.out.println("x="+x+" xi="+xi);
// Results in: x=1.0001 km xi=1000.0 m
...
Comment 2 Werner Keil CLA 2012-08-18 15:26:35 EDT
Fixed by treating Decimal numbers differently from Integer type numbers in BaseAmount when using RationalConverter