How to Get discount amount of an Order in Magento 2?

How to Get Final discount amount of an Order in Magento 2?

An Order has a discount amount field used to store the discount amount value in the sales_order table for the specific order.

discount_amount field used to store final discount value applied to order level.

If the Customer has a discount code and they used to code for place an order time, the amount of discount will be saved to the sales order table with a discount_amount field to track discount value in the future for the order.

By Default, Value will be saved as a negative value in the sales_order table.

if the order has a total amount of discount is $50, the value will be saved in the table like, -50.0000 (Negative number) value.

You can get the discount amount value by order increment id using below code,

If the Order has a discount available, the Result will be displayed as the discount amount. We have used abs() function to convert negative to a positive value for a discount amount.

Output:
The final discount value is the float type and if a discount is not the available result will be null.

How to get Order Discount using the Order Entity Id value instead of Order Increment id?
If You have order entity id available, You don’t need to use search criteria builder to fetch order records, Using get($orderId) method of the Order Repository interface is the simplest way to fetch order record and retrieve the value of getDiscountAmount() from the order.