From: Thomas Heck Date: Tue, 28 Aug 2012 10:38:35 +0000 (+0200) Subject: Merge branch 'master' of vc.linet-services.de:public/lx-office-erp X-Git-Tag: release-3.0.0beta1~271 X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/commitdiff_plain/a1a9bb961ab49ee053cb208ea01e17430d0ca836?hp=abde405dfaab376a13e9a1e3e24cd715fa7de024 Merge branch 'master' of vc.linet-services.de:public/lx-office-erp --- 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;