Link to home
Create AccountLog in
Avatar of sydneyguy
sydneyguyFlag for Australia

asked on

format into a percentage amount instead of 66.66666666 ect to 66

trying to set up a value formatted to cut all off on the right side of the decimal point

<td width="15%" align="right">
                        <span id="perecnt_<?php echo ($i);?>" class="tablchet" ><?php echo sprintf($currmask,0);?></span>
                  </td>


perecntpur.innerHTML = ((1/amtstore) *amtbought) * 100 ; to display


User generated image
SOLUTION
Avatar of plusone3055
plusone3055
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of sydneyguy

ASKER

this is the line that does the maths so its this line that will need the formatting applied to it

perecntpur.innerHTML = ((1/amtstore) *amtbought) * 100 ; to display
am trying this line but does not work

perecntpur.innerHTML =  sprintf("%.0e",((1/amtstore) *amtbought) * 100);
SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
this syntax i would have guessed would have worked but no
perecntpur.innerHTML = round(((1/amtstore) *amtbought) * 100);

val = round(((1/amtstore) *amtbought) * 100);
perecntpur.innerHTML =  val;

any ideas but we are gettgn there
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
round() is a PHP function.

This line of your code...

perecntpur.innerHTML = round(((1/amtstore) *amtbought) * 100);

Open in new window

...does not look like PHP. What is it?
thanks for the help on this question