I have an order_item object and I see a few methods to get the price specifically getUnitPrice() and getTotalPrice(), however each of these returns the numeric value with the currency code append (e.g., "9.99 USD"). I just need the value and would rather not do any regex or string replacement.

Comments

joegl created an issue. See original summary.

joegl’s picture

Title: How to get price without currency code from OrderItem » How to get OrderItem numeric price value without currency code?
joegl’s picture

Status: Active » Closed (works as designed)

I am apparently not a smart person. However, helping future people is worth more than my self-esteem so I'll leave the answer:

$OrderItem->getUnitPrice()->getNumber();

EDIT: This is the full code I used to get the rounded price:

$rounded_item_price = \Drupal::service('commerce_price.rounder')->round($orderItem->getUnitPrice())->getNumber();