@@ -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
@@ -361,13 +361,26 @@ public function pre_save( $value, $id = null, $name = null, $options = null, $fi
361
361
return null ;
362
362
}
363
363
364
+ $ prefix = null ;
365
+
366
+ if (
367
+ 1 === (int ) pods_v ( static ::$ type . '_keep_leading_zeroes ' , $ options , 0 )
368
+ && preg_match ( '/^(0+)/ ' , $ value , $ leading_zeroes )
369
+ ) {
370
+ $ prefix = $ leading_zeroes [0 ];
371
+ }
372
+
364
373
$ value = number_format ( (float ) $ value , $ decimals , '. ' , '' );
365
374
366
375
// Optionally remove trailing decimal zero's.
367
376
if ( pods_v ( static ::$ type . '_format_soft ' , $ options , false ) ) {
368
377
$ value = $ this ->trim_decimals ( $ value , '. ' );
369
378
}
370
379
380
+ if ( null !== $ prefix ) {
381
+ $ value = $ prefix . $ value ;
382
+ }
383
+
371
384
return $ value ;
372
385
}
373
386
@@ -386,6 +399,15 @@ public function format( $value = null, $name = null, $options = null, $pod = nul
386
399
$ dot = $ format_args ['dot ' ];
387
400
$ decimals = $ format_args ['decimals ' ];
388
401
402
+ $ prefix = null ;
403
+
404
+ if (
405
+ 1 === (int ) pods_v ( static ::$ type . '_keep_leading_zeroes ' , $ options , 0 )
406
+ && preg_match ( '/^(0+)/ ' , $ value , $ leading_zeroes )
407
+ ) {
408
+ $ prefix = $ leading_zeroes [0 ];
409
+ }
410
+
389
411
if ( 'i18n ' === pods_v ( static ::$ type . '_format ' , $ options ) ) {
390
412
$ value = number_format_i18n ( (float ) $ value , $ decimals );
391
413
} else {
@@ -397,6 +419,10 @@ public function format( $value = null, $name = null, $options = null, $pod = nul
397
419
$ value = $ this ->trim_decimals ( $ value , $ dot );
398
420
}
399
421
422
+ if ( null !== $ prefix ) {
423
+ $ value = $ prefix . $ value ;
424
+ }
425
+
400
426
return $ value ;
401
427
}
402
428
0 commit comments