Jump to content

[SOLVED] Selecting part of a variable


mrbill

Recommended Posts

Been trying to select part of a number (price) contained in a variable.

 

Here is a sample of the code I have been attempting to get to work for this

$amount = "$52.99";
$n = sscanf($amount, "%s %s", $dollars, $cents);
echo "<h2>" . $dollars . "</h2> <em>" .$cents. "</em>";

 

The above outputs everything to the $dollars and nothing to $cents. The dollar amount won't always be 2 digits so I would like to be able to just seperate from the right to the decimal, that is *.99* only and the dollar amount from the decimal to the dollar sign, *$52*.

 

All I am trying to do is take the $amount which is in this example $52.99 and separate the dollar from the cents so I can apply a style.

 

It should look something like this: $52.99

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.