-4

I have Integer or String value like 6250 or 125... I need like below example. Is it possible in Javascript?

6250 to 62,50
7856 to 78,56
125 to 1,25
050 to 0,50
6
  • You want comma or decimal point? Commented Sep 5, 2014 at 8:23
  • @R.T.decimal good solution for me... Commented Sep 5, 2014 at 8:23
  • Why does 6250 converts to 62,5 1 ? Commented Sep 5, 2014 at 8:25
  • So what did you try so far? Commented Sep 5, 2014 at 8:26
  • @Youness Sorry I need 6250 to >62,50 Commented Sep 5, 2014 at 8:26

2 Answers 2

3
var i = parseInt('6250'),
    res = (i / 100).toFixed(2);
Sign up to request clarification or add additional context in comments.

2 Comments

@mplungjan. Yeah. Does not correct result. But I round 0,25 and multiples. Worked for me. Thank you again.
I do not understand your comment
1

Just try following code..

Demo

var str = "567";
var len=str.length;
if(len>2){
  var res = str.substring(0, len-2)+','+str.substring(len-2,len);
  alert(res);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.