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

  • Home
  • SEARCH
  • 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 8282301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:19:36+00:00 2026-06-08T10:19:36+00:00

I have the number 2.50 stored in a variable called $price which I can

  • 0

I have the number 2.50 stored in a variable called $price which I can pass to a function and it recognizes the value 2.50 however when I try and multiply it with 2 I get the answer 4. I assumed PHP is truncating the original value and then I thought it might be interpreting it as a String as I am getting the value out of an XML document but the manual says that it will correctly recognize it as 2.50 if it were a String. If anyone could shed some light on this I’d really appreciate it.

Edit: Here’s the code I am using-

$Price = new Prices();

// Traverse XML document
foreach ($simpleXML->product as $product) {

    // Gather info from the product array
    $price = $product->price;
    $type = $product->type;
    $price = $Price->getRealPrice($price, $type);
}

function getRealPrice($price, $type) {
    // echo $price returns 2.50

    // Switch statement on type
    case 'Keychain':
        return 1.7 * $price; // This returns 3.4
        break;
}

The fact that 3.4 is being returned is the real problem, it’s as if it is doing 2 * 1.7 even though it should be 2.5; I chose 2.5 * 2 in my original example because it was more obvious to see the problem.

Update:
After I do 1.8 * $price if I echo $price with cast of double I get this: 2.503.6 The two dots kinda freak me out…

  • 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-08T10:19:38+00:00Added an answer on June 8, 2026 at 10:19 am

    Parse the string to a float by using floatval this in the beginning of your function

    function getRealPrice($price, $type) {
       $price = floatval($price);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number stored in an NSMutableString instance which I want to auto
I have a variable called $result which should store all the results from my
Ok so I have a php variable called $contact_id which is inputted from the
I have a number of documents stored in Solr cluster, and want to get
I have an application that calls a number stored by the user. Everything works
i have an account number that is stored in as a query string. How
I have a number of manually written scripts (.sql) for tables, views and stored
I have data stored in three columns of Excel Column A: Serial Number Column
I have this stored procedure: CREATE OR REPLACE PROCEDURE LIQUIDACION_OBTENER ( p_Cuenta IN NUMBER,
I have a text file containing a number of records. Each record is stored

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.