Permalink
Browse files

Using sprintf to convert number into non-scientific notation

  • Loading branch information...
1 parent 43604f6 commit a7f50e0ce7bee96d4247a080cfaaf9e807c06fbb @wnasich wnasich committed Jan 30, 2014
Showing with 2 additions and 5 deletions.
  1. +2 −5 lib/Cake/View/Helper/FormHelper.php
@@ -1173,11 +1173,8 @@ protected function _magicOptions($options) {
!isset($options['step'])
) {
if ($type === 'decimal') {
- if (preg_match('/[0-9]+,([0-9]+)/', $fieldDef['length'], $fieldLenght) && intval($fieldLenght[1]) > 0) {
- $options['step'] = '0.' . str_repeat('0', $fieldLenght[1] - 1) . '1';
- } else {
- $options['step'] = 1;
- }
+ $decimalPlaces = substr($fieldDef['length'], strpos($fieldDef['length'], ',') + 1);
+ $options['step'] = sprintf('%.' . $decimalPlaces . 'F', pow(10, -1 * $decimalPlaces));
} elseif ($type === 'float') {
$options['step'] = 'any';
}

0 comments on commit a7f50e0

Please sign in to comment.