Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8530243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:12:54+00:00 2026-06-11T09:12:54+00:00

I have problems to get my percent counter function to get it work with

  • 0

I have problems to get my percent counter function to get it work with English money format

function calc_proc($price, $savings) {
    $old_price = $price + $savings;

    return (number_format($savings / ($old_price/100)));
}

because of the commas I’m getting bad values

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:12:56+00:00Added an answer on June 11, 2026 at 9:12 am

    First of all you don’t have to use strings in financial calculations but if you still have to use, you should replace commas with dots. For example,

    $a = '1,5';
    $b = '2,1';
    echo $a + $b; //result 3
    
    // you can avoid this, by replacing comma:
    $a = str_replace(',', '.', $a);
    //same for $b
    

    Another solution could be setting locale but you’d have issues with dots after that.

    In your function it’ll look like this:

    function calc_proc($price, $savings) {
        $price = str_replace(',', '.', $price);
        $savings = str_replace(',', '.', $savings);
        $old_price = (float)$price + (float)$savings;
    
        return (number_format($savings / ($old_price/100)));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problems to get generics to work in the following scenario: Delphi provides
I have problems to get rspec running properly to test validates_inclusion_of my migration looks
I have no problems processing jQuery GET requests in a controller, however I cannot
I have 2 major problems with the Flex (4.6) SoapDecoder, I really can't get
I'm have horrendous problems trying to get a JOGL program compiling using Netbeans 6.9.
I'm working on the symfony tutorial jobeet and I have problems to get a
We use Resteasy and have problems figuring how to call some @GET methods. If
I have problems to get the data of a particular cell in my gridview
I have some problems trying to get a bag collection of a class to
In EclipseME project i have problems with breakpoints that never get hit. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.