/    Sign up×
Community /Pin to ProfileBookmark

Getting next highest multiple of 10 for a number

Please help me,I’m having problem getting the next highest multiple of 10 for a number e.g 36
how do I do it in javascript.

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@Warren86Feb 16.2005 — <HTML>

<Head>

<Script Language=JavaScript>

function calcMult(isVal){

tmp = Math.round(isVal/10)*10;
document.forms.test.nMult.value = tmp;
}


</Script>

</Head>

<Body>

<Form name='test'>

Enter an integer: <input type=text size=10 name='nNmbr' onkeyup="calcMult(this.value)"><br>

Next multiple of 10: <input type=text size=10 name='nMult' readonly>

</Form>

</Body>

</HTML>
Copy linkTweet thisAlerts:
@rodentjeFeb 16.2005 — with java it'll be something like this:
[code=php]import java.io.*;
public class goTenUp{
public static void main(String args[] throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(isr);
System.out.println("Give a number");
String s = in.readLine();
int replace = Integer.parsInt(s.charAt(s.length()-1))+1;
s = s.replace(s.charAt(s.length()-1),s.charAt(s.length()-1),replace);
if(s.charAt(s.length())!=0){
s = s.replace(s.charAt(s.length()),s.charAt(s.length()),'0');
}
System.out.println("The next multiple of ten = "+s);
}
}[/code]


I don't know exactly what you want, 31 results in 40, but 30 results in 30 or 40?? Otherwise, delete the if(...){...}

There could be some errors in it, haven't tested it yet...
Copy linkTweet thisAlerts:
@rodentjeFeb 16.2005 — hmmmm, warren's solution looks a bit easier i guess ?
Copy linkTweet thisAlerts:
@PittimannFeb 16.2005 — Hi![i]Originally posted by rodentje [/i]

[B]hmmmm, warren's solution looks a bit easier i guess ? [/B][/QUOTE]
But it rounds down (i. e.: 34 would result in 30). According to the question, 30 to 39 should result in 40...

Cheers - Pit
Copy linkTweet thisAlerts:
@meherauthorFeb 16.2005 — Warren thank you so much
Copy linkTweet thisAlerts:
@Warren86Feb 16.2005 — You're welcome. I appreciate your courtesy. Take care.
Copy linkTweet thisAlerts:
@David_HarrisonFeb 16.2005 — To simplify Warrensfunction calcMult(isVal){

document.forms.test.nMult.value = isVal - isVal%10;

}
Or to get "the next highest multiple of 10" do this:function calcMult(isVal){

document.forms.test.nMult.value = isVal - isVal%10 + 10;

}
×

Success!

Help @meher 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.21,
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,
)...