View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0004044 | Slicer4 | Core: Units | public | 2015-09-14 13:36 | 2018-03-02 11:06 |
Reporter | jcfr | Assigned To | Davide | ||
Priority | normal | Severity | minor | Reproducibility | have not tried |
Status | closed | Resolution | open | ||
Product Version | |||||
Target Version | Slicer 4.5.0-1 | Fixed in Version | Slicer 4.5.0-1 | ||
Summary | 0004044: Value to string conversion should account for precision | ||||
Description | The following snippet illustrates the problem. import math It currently returns: 10^-5 -> 1e-05 m/s whereas the following is expected: 10^-5 -> 0.000 m/s | ||||
Tags | No tags attached. | ||||
Import 2017-06-07 23:51:09: master d9f522cc 2015-09-14 18:16:13 Details Diff |
BUG: MRMLUnitNode: Ensure value to string conversion account for precision Fixes 0004044 By calling "strstream.setf(ios::fixed,ios::floatfield)", it guarantees that the returned string will have a number of decimals equal to the precision (instead of a number of digit equal to precision). This prevents the cut of decimals when we have big numbers. Running the following python snippet in the python interactor before and after integrating this commit illustrates the problem and confirm it is fixed. 8<---8<---8<---8<---8<---8<---8<---8<---8<---8<--- import math l = slicer.modules.units.logic() s = l.GetUnitsScene() n = s.GetNodesByName("Metre per second").GetItemAsObject(0) n.SetPrecision(3) for v in range(-5, 5): print("10^%d -> %s" % (v, n.GetDisplayStringFromValue(math.pow(10, v)))) 8<---8<---8<---8<---8<---8<---8<---8<---8<---8<--- Before the change: 10^-5 -> 1e-05 m/s 10^-4 -> 0.0001 m/s 10^-3 -> 0.001 m/s 10^-2 -> 0.01 m/s 10^-1 -> 0.1 m/s 10^0 -> 1 m/s 10^1 -> 10 m/s 10^2 -> 100 m/s 10^3 -> 1e+03 m/s 10^4 -> 1e+04 m/s After the change: 10^-5 -> 0.000 m/s 10^-4 -> 0.000 m/s 10^-3 -> 0.001 m/s 10^-2 -> 0.010 m/s 10^-1 -> 0.100 m/s 10^0 -> 1.000 m/s 10^1 -> 10.000 m/s 10^2 -> 100.000 m/s 10^3 -> 1000.000 m/s 10^4 -> 10000.000 m/s Co-authored-by: Jean-Christophe Fillion-Robin <jchris.fillionr@kitware.com> From: Davide Punzo <punzodavide@hotmail.it> git-svn-id: http://svn.slicer.org/Slicer4/trunk@24541 3bd1e089-480b-0410-8dfb-8563597acbee |
||
mod - Libs/MRML/Core/vtkMRMLUnitNode.cxx | Diff File |
Date Modified | Username | Field | Change |
---|---|---|---|
2015-09-14 13:36 | jcfr | New Issue | |
2015-09-14 13:36 | jcfr | Status | new => assigned |
2015-09-14 13:36 | jcfr | Assigned To | => Davide |
2015-09-14 14:53 | Davide | Status | assigned => resolved |
2015-09-14 14:53 | Davide | Description Updated | |
2015-09-14 14:57 | jcfr | Note Added: 0013270 | |
2015-09-14 14:57 | jcfr | Fixed in Version | => Slicer 4.5.0-1 |
2015-09-14 14:57 | jcfr | Target Version | => Slicer 4.5.0-1 |
2015-09-14 14:57 | jcfr | Description Updated | |
2017-06-10 08:51 | jcfr | Changeset attached | => Slicer master d9f522cc |
2018-03-02 11:06 | jcfr | Status | resolved => closed |