Skip to content

Commit aec73d5

Browse files
author
Simon Bigelmayr
committed
refactor: Refactor concentration formatting with no sprintf
1 parent 881f591 commit aec73d5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/LightcyclerSampleSheet/AbsoluteQuantificationSample.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MLL\Utils\LightcyclerSampleSheet;
44

5+
use Illuminate\Support\Number;
56
use MLL\Utils\Microplate\Coordinates;
67
use MLL\Utils\Microplate\CoordinateSystem12x8;
78

@@ -43,10 +44,10 @@ public static function formatConcentration(?int $concentration): string
4344
return '';
4445
}
4546

46-
$formatted = sprintf('%.2E', $concentration);
47+
$exponent = (int) floor(log10(abs($concentration)));
48+
$mantissa = $concentration / (10 ** $exponent);
4749

48-
// Remove the + sign from positive exponents to match Lightcycler format (4.00E2 instead of 4.00E+2)
49-
return str_replace('E+', 'E', $formatted);
50+
return Number::format($mantissa, 2) . 'E' . $exponent;
5051
}
5152

5253
/** @return list<string> */

0 commit comments

Comments
 (0)