From fcc1d512a5e2cd9db53702fea9ef83684aa0f2f3 Mon Sep 17 00:00:00 2001 From: Thomas Heck Date: Tue, 28 Aug 2012 12:22:34 +0200 Subject: [PATCH] SL::Form::format_amount formatiert Zahlen auch aus der Exponentialschreibweise. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit +Tests für SL::Form::format_amount fixt #1904 --- SL/Form.pm | 2 ++ t/form/format_amount.t | 44 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 t/form/format_amount.t 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; -- 2.20.1