Numeric Functions

Functions

← Previous
Next →

Numeric Functions

Context

The receiver can only accept unit prices with two decimals. The sender's system is using up to four decimals. In order to transmit four decimals, the receiver is allowing a "price basis factor" to be transmitted. The price basis factor is the quantity the transmitted unit_price refers to. Example:

  • unit_price: 15.55, price_basis_factor: 1 → real unit price: 15.55 (unit_price/factor)
  • unit_price: 15.55, price_basis_factor: 100 → real unit price: 0.1555 (unit_price/factor)

This is how real unit prices with more than two decimals can be transmitted to the receiver.

Task

For each line item, create an object containing the product_id as well as a unit_price and a price_basis. If the unit_price has more than two decimals, use a price_basis of 100 and a unit_price of x*100 to transmit the remaining decimals.

Note: The input uses strings instead of numbers for the unit_price which will have to be cast to numbers before you can do calculations.

Your Expression
Your Result
No data
Input JSON
{
    line_items:[
      {
        product_id:1,
        unit_price:"30.12",
        quantity:10
      },
      {
        product_id:2,
        unit_price:"40.120",
        quantity:50
      },
      {
        product_id:3,
        unit_price:"50.886",
        quantity:5
      },
      {
        product_id:4,
        unit_price:"60.3048",
        quantity:200
      }
    ]
}
Expected Output
[
    {
      product_id:1,
      unit_price:30.12,
      price_basis:1
    },
    {
      product_id:2,
      unit_price:40.12,
      price_basis:1
    },
    {
      product_id:3,
      unit_price:5088.6,
      price_basis:100
    },
    {
      product_id:4,
      unit_price:6030.48,
      price_basis:100
    }
]