From: Thomas Heck Date: Tue, 28 Aug 2012 10:22:34 +0000 (+0200) Subject: SL::Form::format_amount formatiert Zahlen auch aus der Exponentialschreibweise. X-Git-Tag: release-3.0.0beta1~272 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=fcc1d512a5e2cd9db53702fea9ef83684aa0f2f3;p=kivitendo-erp.git SL::Form::format_amount formatiert Zahlen auch aus der Exponentialschreibweise. +Tests für SL::Form::format_amount fixt #1904 --- diff --git a/SL/Form.pm b/SL/Form.pm index 70d3a6550..2f4283359 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -871,6 +871,8 @@ sub format_amount { $amount = 0; } + $amount *= 1; + # Hey watch out! The amount can be an exponential term like 1.13686837721616e-13 my $neg = ($amount =~ s/^-//); diff --git a/t/form/format_amount.t b/t/form/format_amount.t new file mode 100644 index 000000000..2c6e90da8 --- /dev/null +++ b/t/form/format_amount.t @@ -0,0 +1,44 @@ +use strict; +use Test::More; + +use lib 't'; + +use_ok('SL::Form'); +require_ok('SL::Form'); + + +package LxDebugMock; +sub enter_sub {}; +sub leave_sub {}; + +$main::lxdebug = bless({}, 'LxDebugMock'); + +package main; + + +my $form = Form->new(); + + +my $config = {}; + + +$config->{numberformat} = '1.000,00'; + +is($form->format_amount($config, '1e1', 2), '10,00', 'blaa'); +is($form->format_amount($config, 1000, 2), '1.000,00', 'blaa'); +is($form->format_amount($config, 1000.1234, 2), '1.000,12', 'blaa'); +is($form->format_amount($config, 1000000000.1234, 2), '1.000.000.000,12', 'blaa'); +is($form->format_amount($config, -1000000000.1234, 2), '-1.000.000.000,12', 'blaa'); + + +$config->{numberformat} = '1,000.00'; + +is($form->format_amount($config, '1e1', 2), '10.00', 'blaa'); +is($form->format_amount($config, 1000, 2), '1,000.00', 'blaa'); +is($form->format_amount($config, 1000.1234, 2), '1,000.12', 'blaa'); +is($form->format_amount($config, 1000000000.1234, 2), '1,000,000,000.12', 'blaa'); +is($form->format_amount($config, -1000000000.1234, 2), '-1,000,000,000.12', 'blaa'); + +done_testing; + +1;