• Resolved prokops

    (@prokops)


    Hello!

    We import from a sheet that notes prices in €.
    We want to calculate those prices to DKK.
    Furthermore, we want a snippet to round prices up to nearest whole 10 number and then subtract 0.05.

    So a price in € of 100 should get multiplied by 7.44= 744
    Then round up to nearest 10 number = 750
    Then subtract 0.05 = 749.95

    I think php should be:

    function round_price_with_limits( $price = null, $multiplier = 1, $nearest = 10, $minus = 0.05, $map = 0, $msrp = 9999999999) {
    
        // Ensure a price was provided.
        if ( !empty( $price ) ) {
    
            // Calculate price with markup and round it.
            $rounded_price = ( round ( ( $price * $multiplier ) / $nearest ) * $nearest ) - $minus; 
    
            // If price is less than minimum, return minimum.
            if($rounded_price < $map){
    
                return $map;
    
            }
            // If price is greater than maximum, return maximum.
            elseif($rounded_price > $msrp){
    
                return $msrp;
    
            } else {
    
                // Return price otherwise.
                return $rounded_price;
    
            }
    
        }
    }

    Does this seem correct?

Viewing 1 replies (of 1 total)
  • Plugin Author WP All Import

    (@wpallimport)

    HI @prokops,

    Inside your “round_price_with_limits” function, I think that you’ll need to use the “ceil” function instead of “round” since you’re always wanting to round UP to the nearest 10.

Viewing 1 replies (of 1 total)
  • The topic ‘round up pricing decimal’ is closed to new replies.