anyone can explain to me about this | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

30th Apr 2018, 7:37 PM
Hafizd Jubaidir
Hafizd Jubaidir - avatar
38 Answers
+ 2
hafizd21j then use "500.000000" to make it a string, and not a value; for display there is no difference
30th Apr 2018, 7:55 PM
Roel
Roel - avatar
+ 4
you put 500.000000, everything after "." is decimal, so 500.000000= 500
30th Apr 2018, 7:43 PM
Amar
Amar - avatar
+ 4
this.price.toFixed (6)
30th Apr 2018, 8:24 PM
Nommer101
Nommer101 - avatar
+ 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." 😂.
1st May 2018, 1:54 PM
Amar
Amar - avatar
+ 2
if he wants it to be changable, he just needs to make a code to enter a new string
30th Apr 2018, 8:12 PM
Roel
Roel - avatar
+ 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 '.'.
30th Apr 2018, 8:29 PM
Nommer101
Nommer101 - avatar
+ 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.
30th Apr 2018, 9:03 PM
Amar
Amar - avatar
+ 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.
30th Apr 2018, 9:06 PM
Nommer101
Nommer101 - avatar
+ 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.
30th Apr 2018, 9:16 PM
Nommer101
Nommer101 - avatar
+ 2
Better to try and fail than to never try at all.
1st May 2018, 11:07 AM
Nommer101
Nommer101 - avatar
+ 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
1st May 2018, 11:38 AM
Roel
Roel - avatar
+ 1
Amar oh ok ,so how to order 500.000000 shown ? .
30th Apr 2018, 7:45 PM
Hafizd Jubaidir
Hafizd Jubaidir - avatar
+ 1
hmm okay i will try it, thank you all already answer my question
30th Apr 2018, 7:58 PM
Hafizd Jubaidir
Hafizd Jubaidir - avatar
+ 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
30th Apr 2018, 8:17 PM
Amar
Amar - avatar
+ 1
hafizd21j use Nommer101 his answer, hes way better in javascript and its way shorter
30th Apr 2018, 8:26 PM
Roel
Roel - avatar
+ 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.
30th Apr 2018, 8:33 PM
Nommer101
Nommer101 - avatar
+ 1
that isn't problem, problem is when it needs to be calculated in program and not entered. 😁
30th Apr 2018, 9:12 PM
Amar
Amar - avatar
+ 1
I'm not that good with formatting in javascript, and I can't say anything on that topic. 😁
30th Apr 2018, 9:13 PM
Amar
Amar - avatar
+ 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? 😁
1st May 2018, 4:28 AM
Amar
Amar - avatar
+ 1
Roel write the code 😉 and show us
1st May 2018, 11:00 AM
Nommer101
Nommer101 - avatar