Putting a + or - in front of a number in a table
Putting a + or - in front of a number in a table
I am putting numbers into a html table to display the pluses or minuses on a players inventory item. The negative numbers show up with a minus but the positive numbers are just showing up with the number and no plus sign.
I'm just curious if there is an html or css formatting command that I can use to have a plus show up in front of positive numbers? If not I will add if statements in my php to check if the numbers are positive and then concatenate the + onto the numbers.
Thanks for any suggestions anyone has.
I'm just curious if there is an html or css formatting command that I can use to have a plus show up in front of positive numbers? If not I will add if statements in my php to check if the numbers are positive and then concatenate the + onto the numbers.
Thanks for any suggestions anyone has.
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Putting a + or - in front of a number in a table
Hmm...I have never actually dealt with this myself, but I wonder if <pre> may handle it? Often, <pre></pre> tags are used to format programming code because it tells the HTML rendering engine that you have preformatted the text and not to mess with it.
Maybe try that, and see what effect that has. It would keep unnecessary strain off of your server if you could create a client-side option to ensure the pluses show.
Maybe try that, and see what effect that has. It would keep unnecessary strain off of your server if you could create a client-side option to ensure the pluses show.
The indelible lord of tl;dr
Re: Putting a + or - in front of a number in a table
Thanks for the reply Jackolantern.
I checked out the pre tag but it looks like I still have to put what I want to create inside the pre tags.
I can do that or I can just concatenate the + onto the number. Was just curious if there was a html or css tag that would make numbers show up with a plus automaticly. Thanks again for the suggestion.
I checked out the pre tag but it looks like I still have to put what I want to create inside the pre tags.
I can do that or I can just concatenate the + onto the number. Was just curious if there was a html or css tag that would make numbers show up with a plus automaticly. Thanks again for the suggestion.
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Putting a + or - in front of a number in a table
hmm not sure on that one, i think a if statement may be the option
Code: Select all
if($variable > 0){$modifier = "+";}else {modifier = "";}
echo "Rocks=" . $modifier . $info3['rocks'];- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Putting a + or - in front of a number in a table
I would honestly do it with Javascript, particularly if you are going to be having to process it on many different numbers in a table. I typically try to leave simple, presentation-oriented processing like that on the client-side, particularly if you are creating something that will demand Javascript be on, such as a game.
The indelible lord of tl;dr
Re: Putting a + or - in front of a number in a table
A short hand if would be handier and quicker for this. No need for defining a variable.hallsofvallhalla wrote:hmm not sure on that one, i think a if statement may be the option
Code: Select all
if($variable > 0){$modifier = "+";}else {modifier = "";} echo "Rocks=" . $modifier . $info3['rocks'];
Code: Select all
echo 'Rocks=' . $var < 0 ? '-' : '' . $info3['rocks'] Fighting for peace is declaring war on war. If you want peace be peaceful.
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Putting a + or - in front of a number in a table
very pretty!
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Putting a + or - in front of a number in a table
Ok, I did a couple of tests on my own, and I don't quite understand the problem. Unless I am missing something, or did not do something right, when I did my tests, a simple "+" stayed in front of the numbers I put into table cells without any CSS, JS or additional tags. Is this maybe an issue with a certain browser, or did I maybe do something different?
The indelible lord of tl;dr
Re: Putting a + or - in front of a number in a table
Reading over this topic again, I think you might be looking for the CSS content tag:
CSS
HTML:
CSS
Code: Select all
.pos:before {
content: '+';
}Code: Select all
<table>
<tr>
<th> Nº </th>
</tr>
<tr>
<td class="pos">1</td>
</tr>
<tr>
<td>-1</td>
</tr>
<tr>
<td class="pos">69</td>
</tr>
<tr>
<td class="pos">48</td>
</tr>
<tr>
<td>-91</td>
</tr>
</table>
Fighting for peace is declaring war on war. If you want peace be peaceful.