@@ -157,7 +157,7 @@ public function schema( $options = null ) {
157
157
158
158
$ schema = 'DECIMAL( ' . $ length . ', ' . $ decimals . ') ' ;
159
159
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 ) ) {
161
161
$ schema = 'VARCHAR( ' . $ length . ') ' ;
162
162
}
163
163
@@ -358,13 +358,26 @@ public function pre_save( $value, $id = null, $name = null, $options = null, $fi
358
358
return null ;
359
359
}
360
360
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
+
361
370
$ value = number_format ( (float ) $ value , $ decimals , '. ' , '' );
362
371
363
372
// Optionally remove trailing decimal zero's.
364
373
if ( pods_v ( static ::$ type . '_format_soft ' , $ options , false ) ) {
365
374
$ value = $ this ->trim_decimals ( $ value , '. ' );
366
375
}
367
376
377
+ if ( null !== $ prefix ) {
378
+ $ value = $ prefix . $ value ;
379
+ }
380
+
368
381
return $ value ;
369
382
}
370
383
@@ -383,6 +396,15 @@ public function format( $value = null, $name = null, $options = null, $pod = nul
383
396
$ dot = $ format_args ['dot ' ];
384
397
$ decimals = $ format_args ['decimals ' ];
385
398
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
+
386
408
if ( 'i18n ' === pods_v ( static ::$ type . '_format ' , $ options ) ) {
387
409
$ value = number_format_i18n ( (float ) $ value , $ decimals );
388
410
} else {
@@ -394,6 +416,10 @@ public function format( $value = null, $name = null, $options = null, $pod = nul
394
416
$ value = $ this ->trim_decimals ( $ value , $ dot );
395
417
}
396
418
419
+ if ( null !== $ prefix ) {
420
+ $ value = $ prefix . $ value ;
421
+ }
422
+
397
423
return $ value ;
398
424
}
399
425
0 commit comments