?
Solved

format into a percentage amount instead of 66.66666666 ect to 66

Posted on 2013-11-19
8
Medium Priority
?
229 Views
Last Modified: 2013-11-23
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


format
0
Comment
Question by:sydneyguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 22

Assisted Solution

by:plusone3055
plusone3055 earned 600 total points
ID: 39659269
Referenced from
http://php.net/manual/en/function.sprintf.php

<?php
$number = 362525200;

echo sprintf("%.0e", $number); // outputs 3.625e+8
?>

This should give you the percentage format you need :)
0
 

Author Comment

by:sydneyguy
ID: 39659277
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
0
 

Author Comment

by:sydneyguy
ID: 39659281
am trying this line but does not work

perecntpur.innerHTML =  sprintf("%.0e",((1/amtstore) *amtbought) * 100);
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 44

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 600 total points
ID: 39659295
In PHP you have the round function, will will round a float to an int. If you just want to trim of the decimals then you have floor(). innerHTML is Javascript so I'm confused as to which language you're referring to:

$number = 66.66666666;

echo round($number); // will echo 67
echo floor($number); // will echo 66

Open in new window

No idea why you're trying to format your number in scientific notation
0
 

Author Comment

by:sydneyguy
ID: 39659328
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
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 800 total points
ID: 39659333
Here is how I would do it in PHP, assuming that you have the data in PHP and you're not constrained to use only client-side data.

http://www.laprbass.com/RAY_temp_sydneyguy.php

Outputs:
0.666666666667
0.67
67%
66.7%

<?php // RAY_temp_sydneyguy.php
error_reporting(E_ALL);
echo '<pre>';


// http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28297972.html
// FORMAT A PERCENTAGE VALUE


// CREATE A REPEATING DECIMAL
$x = 2.0 / 3.0;
echo $x;
echo PHP_EOL;

// TURN IT INTO A USEFUL DECIMAL VALUE
$y = number_format($x, 2);
echo $y;
echo PHP_EOL;

// TURN IT INTO A PERCENTAGE
$z = number_format($x * 100, 0) . '%';
echo $z;echo PHP_EOL;

// TURN IT INTO A PERCENTAGE
$z = number_format($x * 100, 1) . '%';
echo $z;echo PHP_EOL;

Open in new window

0
 
LVL 44

Expert Comment

by:Chris Stanyon
ID: 39659470
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?
0
 

Author Closing Comment

by:sydneyguy
ID: 39670961
thanks for the help on this question
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question