Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Webflow

WebflowMapper::price_to_decimalprivateWC 1.0

Convert a Webflow money object { value: int (minor units), unit: "USD" } into a decimal string.

The number of minor units per major unit varies by currency (e.g. JPY has 0, KWD has 3, most have 2), so the divisor is derived from the currency's num_decimals rather than a hardcoded / 100.

Method of the class: WebflowMapper{}

No Hooks.

Returns

String|null.

Usage

// private - for code of main (parent) class only
$result = $this->price_to_decimal( $money ): ?string;
$money(mixed) (required)
Webflow money object.

WebflowMapper::price_to_decimal() code WC 11.0.0

private function price_to_decimal( $money ): ?string {
	if ( ! is_object( $money ) || ! isset( $money->value ) ) {
		return null;
	}
	$minor = (int) $money->value;
	if ( $minor < 0 ) {
		return null;
	}
	$unit     = isset( $money->unit ) ? (string) $money->unit : 'USD';
	$decimals = $this->get_currency_decimals( $unit );
	return number_format( $minor / ( 10 ** $decimals ), $decimals, '.', '' );
}