@@ -157,7 +157,7 @@ public function schema( $options = null ) {
157157
158158 $ schema = 'DECIMAL( ' . $ length . ', ' . $ decimals . ') ' ;
159159
160- if ( 1 === (int ) pods_v ( static ::$ type . '_keep_leading_zeroes ' , $ options , 255 ) ) {
160+ if ( 1 === (int ) pods_v ( static ::$ type . '_keep_leading_zeroes ' , $ options , 0 ) ) {
161161 $ schema = 'VARCHAR( ' . $ length . ') ' ;
162162 }
163163
@@ -358,13 +358,26 @@ public function pre_save( $value, $id = null, $name = null, $options = null, $fi
358358 return null ;
359359 }
360360
361+ $ prefix = null ;
362+
363+ if (
364+ 1 === (int ) pods_v ( static ::$ type . '_keep_leading_zeroes ' , $ options , 0 )
365+ && preg_match ( '/^(0+)/ ' , $ value , $ leading_zeroes )
366+ ) {
367+ $ prefix = $ leading_zeroes [0 ];
368+ }
369+
361370 $ value = number_format ( (float ) $ value , $ decimals , '. ' , '' );
362371
363372 // Optionally remove trailing decimal zero's.
364373 if ( pods_v ( static ::$ type . '_format_soft ' , $ options , false ) ) {
365374 $ value = $ this ->trim_decimals ( $ value , '. ' );
366375 }
367376
377+ if ( null !== $ prefix ) {
378+ $ value = $ prefix . $ value ;
379+ }
380+
368381 return $ value ;
369382 }
370383
@@ -383,6 +396,15 @@ public function format( $value = null, $name = null, $options = null, $pod = nul
383396 $ dot = $ format_args ['dot ' ];
384397 $ decimals = $ format_args ['decimals ' ];
385398
399+ $ prefix = null ;
400+
401+ if (
402+ 1 === (int ) pods_v ( static ::$ type . '_keep_leading_zeroes ' , $ options , 0 )
403+ && preg_match ( '/^(0+)/ ' , $ value , $ leading_zeroes )
404+ ) {
405+ $ prefix = $ leading_zeroes [0 ];
406+ }
407+
386408 if ( 'i18n ' === pods_v ( static ::$ type . '_format ' , $ options ) ) {
387409 $ value = number_format_i18n ( (float ) $ value , $ decimals );
388410 } else {
@@ -394,6 +416,10 @@ public function format( $value = null, $name = null, $options = null, $pod = nul
394416 $ value = $ this ->trim_decimals ( $ value , $ dot );
395417 }
396418
419+ if ( null !== $ prefix ) {
420+ $ value = $ prefix . $ value ;
421+ }
422+
397423 return $ value ;
398424 }
399425
0 commit comments