+ 3
anyone can explain to me about this
why the show is only 500 should be 500.000000, why ?, please explain to me. https://code.sololearn.com/WJ3ZyQzLMVEu/?ref=app
38 Answers
+ 2
hafizd21j then use "500.000000" to make it a string, and not a value; for display there is no difference
+ 4
you put 500.000000, everything after "." is decimal,
so 500.000000= 500
+ 4
this.price.toFixed (6)
+ 3
I don't think that showed if statement will do the job. Lets say that 500000000 is value of x, and length of it converted to string is 9, and 9%3==0, so condition is met. x+="." would print "500000000." 😂.
+ 2
if he wants it to be changable, he just needs to make a code to enter a new string
+ 2
Number has a prototype method used for fixed amount of decimal places. The number you pass in is the amount of decimal place you want to have after the '.'.
+ 2
I assumed that he wanted 500 million but seperated with dots for easier readability, because his price is expressed in Rp, and it didn't make sense to me to express price with 6 decimals. 😁
However nice work Nommer101. Good luck.
+ 2
In that case formatting would work better thou then you can do custom separators. You need to enter right amount thou for calculations so that you do not end up with wrong amounts.
+ 2
Then thats a good reason to make it a challenge so you can see how others approach the problem but its not a very difficult problem if you do not go over board. Trying to cater for every possible way to format currency.
+ 2
Better to try and fail than to never try at all.
+ 2
var x=500000000;
x.toString();
if(x.length % 3==0){
x+=".";
}
else{}
var m = new myMotor("Si Jagur","yangmana",x,2018);
m.showAll();
this should do the job, but i dont know how to add spaces or points
+ 1
Amar oh ok ,so how to order 500.000000 shown ? .
+ 1
hmm okay i will try it, thank you all already answer my question
+ 1
i deleted my answer, because i couldn't explain what I thought of.
what if price needs to be calculated (right now he's just wirting it directly), even converting to string will make it 500 again? that's where real problem is
+ 1
You're welcome let me know if you get stuck on anything else or want to learn more about prototyping. Looks like you might need it soon if you are working with javascript classes.
+ 1
that isn't problem, problem is when it needs to be calculated in program and not entered. 😁
+ 1
I'm not that good with formatting in javascript, and I can't say anything on that topic. 😁
+ 1
Roel, when it's finished calculating and he has 500 000 000, it will print as 500000000, how to put speretaros between thousands or million? 😁
+ 1
Roel write the code 😉 and show us