/    Sign up×
Community /Pin to ProfileBookmark

Im using JS to divide a big number…

ie.. 1,660,300 / 1,000,000 so i don’t have lots of numbers everwhere..

However when i do this i still get 1.6603 which is still too long..

How do I use the Math function to edit this number to 1 decimal place…

so instead of showing 1.6603 it would show 1.7?

Thanks

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@CharlesSep 30.2006 — [code=html]<pre>
<script type="text/javascript">
document.writeln (Math.PI.toFixed (1))
</script>
</pre>[/code]
Copy linkTweet thisAlerts:
@DistantUKauthorSep 30.2006 — how would i implement this here

[code=html]if ( technocost >= 1000000000000 ) {
var newcost = ( technocost / 1000000000000 );
var techcost = ''+newcost+' T' ; }
else {
var techcost = techcost ; }[/code]
Copy linkTweet thisAlerts:
@samanyoluSep 30.2006 — [code=php]

<html>
<head>
<title></title>
<meta content="">
<script type="text/javascript">
function calculate(){
technocost=123.453
if ( technocost >= 100 ) {
var newcost = technocost.toFixed(1);
alert(newcost); // 123.5
var techcost = ''+newcost+' T' ;
alert(techcost); } // 123.5T
else {
var techcost = techcost ;
alert(techcost);
}

}
calculate()
</script>
<style></style>
</head>
<body></body>
</html>

[/code]
Copy linkTweet thisAlerts:
@DistantUKauthorSep 30.2006 — ok..

this is what i have

[CODE]
if ( humanavgp >= 1000 )
{
var havgpshort = Math.round( humanavgp / 1000 ) ;
var havgpshort= havgpshort.toFixed(1);
var resulthavgp = ''+havgpshort+' k' ;
}
else
{
var resulthavgp = havgp ;
}[/CODE]


however, the answer always show as x.0, there is never a number after the decimal place except for 0, and if thats the case there is no point in using the code, have i done something wrong?
Copy linkTweet thisAlerts:
@samanyoluSep 30.2006 — [code=php]

<html>
<head>
<title></title>
<meta content="">
<script type="text/javascript">

number=1999.589
number=Math.round(number*10)/10

alert(number); // 1999.6

</script>
</head>
<body></body>
</html>
[/code]


[code=php]
<html>
<head>
<title></title>
<meta content="">
<script type="text/javascript">

number=1999.589
number=number.toFixed(1);
alert(number); // 1999.6

</script> <style></style>
</head>
<body></body>
</html>
[/code]

[code=php]
<script type="text/javascript">

var numara = 12.99999;

numara = numara * 10;

//alert(numara)

numara = parseInt(numara);

//alert(numara)

numara = numara / 10; /

alert(numara) // 12.9

</script>[/code]
×

Success!

Help @DistantUK spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...