Project

General

Profile

Actions

Defect #12510

closed

Issues PDF export: Spent time/Float-values aren't rounded to 2 digits

Added by Luboš Schrámek over 11 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
PDF export
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

Hello,

How to simulate problem?
  • add Spent time column to issues
  • modify Spent time in some issue to 2.45
  • export table to PDF

There will be a columns Spent time with 2.45000004768372. I hope there are missing some number format func(), can you please fix this problem? I am making these exports for customers and it looks bad.

Thanks.


Files

export.pdf (311 KB) export.pdf error in pdf fangzheng (方正), 2012-12-07 07:07
pdf.patch (436 Bytes) pdf.patch get pretty float values for spent time and estimated time Filou Centrinov, 2013-02-12 01:44
pdf.rb.patch (531 Bytes) pdf.rb.patch Filou Centrinov, 2013-03-06 12:36
web-edit.png (4.52 KB) web-edit.png Toshi MARUYAMA, 2013-08-05 12:06
0001-Round-floats-to-2-digits-when-rendering-an-issue-lis.patch (739 Bytes) 0001-Round-floats-to-2-digits-when-rendering-an-issue-lis.patch Holger Just, 2014-10-29 15:34
before.png (79.7 KB) before.png Marius BĂLTEANU, 2017-11-27 01:46
after.png (63.8 KB) after.png Marius BĂLTEANU, 2017-11-27 01:46
0001-Round-floats-to-2-digits-when-rendering-an-issue-lis_r17055.patch (2.21 KB) 0001-Round-floats-to-2-digits-when-rendering-an-issue-lis_r17055.patch Marius BĂLTEANU, 2017-12-06 14:31

Related issues

Related to Redmine - Defect #13780: Spent hours have excessive flaction in PDF exported ticket listClosed

Actions
Related to Redmine - Defect #28233: IssuesPdfHelperTest fails when run in isolationClosedGo MAEDA

Actions
Actions #1

Updated by fangzheng (方正) over 11 years ago

Mark. Waiting for solution.
BTW, this issue doesn't occur on CSV.

Actions #2

Updated by Filou Centrinov about 11 years ago

I'm seeing the same problem in Redmine 2.2.1.
In my Database the spent time values is for example 0.1, but the pdf export displays 0.100000001490116.

Actions #3

Updated by Daniel Felix about 11 years ago

Maybe this relates to the float_max like #12680?

Actions #4

Updated by Daniel Felix about 11 years ago

  • Priority changed from High to Normal
Actions #5

Updated by Filou Centrinov about 11 years ago

Daniel Felix wrote:

Maybe this relates to the float_max like #12680?

Yes, obviously both bugs (this ticket and #12680) have the same causation (floating point error):

UPDATE: No. It does not relate to #12680.

Actions #6

Updated by Filou Centrinov about 11 years ago

To get pretty float values for spent time and estimated time I created this patch: /lib/redmine/export/ pdf.patch

If the value is empty or zero the pdf cell keeps empty, so you get a better overview on spent and estimated hours.

Could you merge this to redmine?

Actions #7

Updated by Filou Centrinov about 11 years ago

Please, could you fix this with redmine 2.3?

Actions #8

Updated by Daniel Felix about 11 years ago

Filou Centrinov wrote:

UPDATE: No. It does not relate to #12680.

Why not? It seems for me to be again some floating point error, which we've encounter many times in different systems.

Actions #9

Updated by Filou Centrinov about 11 years ago

Daniel Felix wrote:

Why not? It seems for me to be again some floating point error, which we've encounter many times in different systems.

The difference is: In #12680 the number is too big, so the floating precision can not be provided. In this issue we are within the floating precision, so the correct presentation should be provided.

The problem is internal caused by displaying a value with a higher precision then the value originaly had. So 0.1 becomes 0.100000001490116, because the type of variable had a precision of 32bit that allows only 8 positions after decimal point. Therefore this problem can easly fixed by: "%.2f" % value
See: pdf.rb.patch

Actions #10

Updated by Filou Centrinov about 11 years ago

In /lib/redmine/i18n.rb is a function called l_hours to format hours into a value+label string. If this function would'nt be used in /app/view/issues/show.html.erb you get the same effect of displayed spent time.

So l_hours fixes the same "bug", but with an additional label.

Actions #12

Updated by Filou Centrinov over 10 years ago

Please fix this. It's a small fix. ... or make it to a candidate.

Actions #13

Updated by Etienne Massip over 10 years ago

  • Status changed from New to Confirmed
  • Target version set to Candidate for next minor release

I can confirm the defect although I'm not fond of the patch, is it possible to fix every single float value display at once rather than specific attributes?

Edit: confirmed with MRI 1.9.3

Actions #14

Updated by David Lukas Müller over 10 years ago

+1
For the particular issue I've observed that on Redmine 2.3.1 I had the following time entries:
  • 3.50h
  • 1.25h
  • 0.30h (I think I've entered "0:20")
And that is what I see:
  • 5.05 with Web User Interface (HTML) --> good
  • 5.050000011920929 with PDF-Export --> chould be improved
  • "spent_hours":5.050000011920929 with REST API (JSON) using http://myhost/redmine/issues/1234.json --> chould be improved
Actions #15

Updated by Toshi MARUYAMA over 10 years ago

David Lukas Müller wrote:

  • 5.05 with Web User Interface (HTML) --> good

Web edit form has same problem.

Actions #16

Updated by Toshi MARUYAMA over 10 years ago

You can see by following change.

diff --git a/app/views/issues/_attributes.html.erb b/app/views/issues/_attributes.html.erb
--- a/app/views/issues/_attributes.html.erb
+++ b/app/views/issues/_attributes.html.erb
@@ -63,7 +63,7 @@
 <% end %>

 <% if @issue.safe_attribute? 'estimated_hours' %>
-<p><%= f.text_field :estimated_hours, :size => 3, :disabled => !@issue.leaf?, :required => @issue.required_attribute?('estimated_hours') %> <%= l(:field_hours) %></p>
+<p><%= f.text_field :estimated_hours, :size => 6, :disabled => !@issue.leaf?, :required => @issue.required_attribute?('estimated_hours') %> <%= l(:field_hours) %></p>
 <% end %>

 <% if @issue.safe_attribute?('done_ratio') && @issue.leaf? && Issue.use_field_for_done_ratio? %>

Actions #17

Updated by Holger Just over 9 years ago

The attached patch (which was extracted from Planio) fixes this issue for all float values in table cells. This patch thus addresses the concerns of Etienne above.

The patch works agains current trunk but should apply similarly to earlier versions. The used method is the one used in the QueriesHelper#column_value method and thus should produce results similar to it.

Actions #18

Updated by Jan from Planio www.plan.io over 9 years ago

  • Assignee set to Jean-Baptiste Barth

In case you were still looking for easy fixes :)

Actions #19

Updated by Jean-Baptiste Barth over 9 years ago

  • Affected version changed from 2.1.2 to 2.6.0

I do :) First I'll try to add some tests to this part of the code but no pb I'll merge it after.

Actions #20

Updated by Olivier Houdas over 7 years ago

Tested on 3.3.1, still occurs.

Actions #21

Updated by S. Ruttloff over 6 years ago

Problem still exists in Redmine 3.3.2, but could fix it here:
/lib/redmine/export/pdf/issues_pdf_helper.rb

Search for

if value.is_a?(Date)
    format_date(value)
elsif value.is_a?(Time)
    format_time(value)
else
    value
end

and replace by

if value.is_a?(Date)
    format_date(value)
elsif value.is_a?(Time)
    format_time(value)
elsif value.is_a?(Float)
    sprintf "%.2f", value
else
    value
end

Actions #22

Updated by Marius BĂLTEANU over 6 years ago

Tested on current trunk (r17037) and the issue still occurs.

I've updated the patch from Holger Just to apply cleanly. I think that we can fix this issue in the next release.

Before:

After:

Actions #23

Updated by Mischa The Evil over 6 years ago

We might want some test coverage added if there isn't any yet, as Jean-Baptiste already suggested.

Actions #24

Updated by Marius BĂLTEANU over 6 years ago

  • File deleted (0001-Round-floats-to-2-digits-when-rendering-an-issue-lis_r17037.patch)
Actions #25

Updated by Marius BĂLTEANU over 6 years ago

  • File 0001-Round-floats-to-2-digits-when-rendering-an-issue-lis_r17055.patch added

Mischa The Evil wrote:

We might want some test coverage added if there isn't any yet, as Jean-Baptiste already suggested.

Attached an updated patch that contains the fix and a test strictly for this scenario. On top of this patch, we can add more tests in the future to improve the coverage.

Actions #26

Updated by Mischa The Evil over 6 years ago

  • Subject changed from Issues PDF export - Spent time to Issues PDF export: Spent time/Float-values aren't rounded to 2 digits.
  • Target version changed from Candidate for next minor release to 4.1.0

Thanks Holger and Marius.

Actions #27

Updated by Marius BĂLTEANU over 6 years ago

  • File deleted (0001-Round-floats-to-2-digits-when-rendering-an-issue-lis_r17055.patch)
Actions #28

Updated by Marius BĂLTEANU over 6 years ago

  • File 0001-Round-floats-to-2-digits-when-rendering-an-issue-lis_r17055.patch added

I had a typo in my previous patch.

Maybe we can deliver this fix earlier than Redmine 4.

Actions #29

Updated by Go MAEDA over 6 years ago

Marius, thank you for adding a test. But I encountered the following error. Could you look into it?

$ ruby test/unit/lib/redmine/export/pdf/issues_pdf_test.rb
Run options: --seed 32491

# Running:

F

Failure:
IssuesPdfHelperTest#test_fetch_row_values_should_round_float_values [test/unit/lib/redmine/export/pdf/issues_pdf_test.rb:32]:
--- expected
+++ actual
@@ -1 +1 @@
-["2", "Add ingredients categories", "4.34"]
+["2", "Add ingredients categories", "0.00"]

bin/rails test test/unit/lib/redmine/export/pdf/issues_pdf_test.rb:23

Finished in 0.658523s, 1.5185 runs/s, 1.5185 assertions/s.
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
Actions #30

Updated by Marius BĂLTEANU over 6 years ago

  • File deleted (0001-Round-floats-to-2-digits-when-rendering-an-issue-lis_r17055.patch)
Actions #32

Updated by Go MAEDA over 6 years ago

  • Status changed from Confirmed to Closed
  • Assignee set to Go MAEDA
  • Target version changed from 4.1.0 to 4.0.0
  • Resolution set to Fixed

Committed in the trunk (r17059). Thank you.

Actions #33

Updated by Toshi MARUYAMA over 6 years ago

  • Subject changed from Issues PDF export: Spent time/Float-values aren't rounded to 2 digits. to Issues PDF export: Spent time/Float-values aren't rounded to 2 digits
Actions #34

Updated by Marius BĂLTEANU about 6 years ago

  • Related to Defect #28233: IssuesPdfHelperTest fails when run in isolation added
Actions #35

Updated by Go MAEDA about 6 years ago

A fix for issues_pdf_test was submitted as #28233. I committed the fix in r17212.

Actions

Also available in: Atom PDF