プロジェクト

全般

プロフィール

Vote #72907

完了

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

Admin Redmine さんが約4年前に追加. 約4年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
PDF export_39
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
39
version_id:
99
issue_org_id:
12510
author_id:
68181
assigned_to_id:
332
comments:
35
status_id:
5
tracker_id:
1
plus1:
1
affected_version:
closed_on:
affected_version_id:
81
ステータス-->[Closed]

説明

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.


journals

Mark. Waiting for solution.
BTW, this issue doesn't occur on CSV.
--------------------------------------------------------------------------------
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.

--------------------------------------------------------------------------------
Maybe this relates to the float_max like #12680?
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
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):-
* "0.1 -> IEEE754 Single precision 32-bit":http://www.binaryconvert.com/result_float.html?decimal=048046049
* -"999999999999999999999999999999 -> IEEE754 Single precision 32-bit":http://www.binaryconvert.com/result_float.html?decimal=057057057057057057057057057057057057057057057057057057057057057057057057057057057057057057-

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

--------------------------------------------------------------------------------
To get pretty float values for spent time and estimated time I created this patch: /lib/redmine/export/ attachment:"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?

--------------------------------------------------------------------------------
Please, could you fix this with redmine 2.3?
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
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: <code>"%.2f" % value</code>
See: attachment:"pdf.rb.patch"

--------------------------------------------------------------------------------
In /lib/redmine/i18n.rb is a function called <code>l_hours</code> 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 <code>l_hours</code> fixes the same "bug", but with an additional label.

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Please fix this. It's a small fix. ... or make it to a candidate.
--------------------------------------------------------------------------------
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_
--------------------------------------------------------------------------------
+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*

--------------------------------------------------------------------------------
David Lukas Müller wrote:
> * @5.05@ with Web User Interface (HTML) --> *good*

Web edit form has same problem.
!web-edit.png!
--------------------------------------------------------------------------------
You can see by following change.

<pre><code class="diff">
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? %>

</code></pre>
--------------------------------------------------------------------------------
The attached patch (which was extracted from "Planio":https://plan.io) 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.
--------------------------------------------------------------------------------
In case you were still looking for easy fixes :)
--------------------------------------------------------------------------------
I do :) First I'll try to add some tests to this part of the code but no pb I'll merge it after.
--------------------------------------------------------------------------------
Tested on 3.3.1, still occurs.
--------------------------------------------------------------------------------
Problem still exists in Redmine 3.3.2, but could fix it here:
/lib/redmine/export/pdf/issues_pdf_helper.rb

Search for
<pre>
if value.is_a?(Date)
format_date(value)
elsif value.is_a?(Time)
format_time(value)
else
value
end
</pre>

and replace by
<pre>
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
</pre>
--------------------------------------------------------------------------------
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:*
!before.png!

*After:*
!after.png!
--------------------------------------------------------------------------------
We might want some test coverage added if there isn't any yet, as Jean-Baptiste already suggested.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
Thanks Holger and Marius.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
I had a typo in my previous patch.

Maybe we can deliver this fix earlier than Redmine 4.
--------------------------------------------------------------------------------
Marius, thank you for adding a test. But I encountered the following error. Could you look into it?

<pre>
$ 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
</pre>
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
It should be fine now.
--------------------------------------------------------------------------------
Committed in the trunk (r17059). Thank you.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

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


related_issues

relates,Closed,13780,Spent hours have excessive flaction in PDF exported ticket list
relates,Closed,28233,IssuesPdfHelperTest fails when run in isolation

Admin Redmine さんが約4年前に更新

  • カテゴリPDF export_39 にセット
  • 対象バージョン4.0.0_99 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0