$exp ) { throw new \InvalidArgumentException( 'Too many decimal places.' ); } $frac = str_pad( $frac, $exp, '0' ); return new self( (int) ( $whole . $frac ), $currency ); } /** Format as the decimal string PayPal expects, e.g. 1099 USD -> "10.99". */ public function toDecimalString(): string { $exp = self::exponent( $this->currency ); if ( 0 === $exp ) { return (string) $this->minor; } $s = str_pad( (string) $this->minor, 3, '0', STR_PAD_LEFT ); return substr( $s, 0, -2 ) . '.' . substr( $s, -2 ); } }