-3
How do I get this one 0. of the account below..
$idMark = 6;
$rating[5] = 4;
$bar5estrelas = ($ratings[5] == 0) ? 0 : round(($ratings[5]/$idMark), 2);
Resultado: 0.67
As the retreat the 0. leaving only 67 ?
-3
How do I get this one 0. of the account below..
$idMark = 6;
$rating[5] = 4;
$bar5estrelas = ($ratings[5] == 0) ? 0 : round(($ratings[5]/$idMark), 2);
Resultado: 0.67
As the retreat the 0. leaving only 67 ?
1
I don’t know if to say what the best way to do it is because I don’t know what the goal will be, since your code seems to me something with a percentage but I can’t be sure what you really want to do
However you can try:
round(($ratings[5]/$idMark), 2) * 100;
Or you can try to convert to string and take the 0. com str_replace
(I believe php already converts to string when we use functions with str_
for example):
str_replace('0.', '', round(($ratings[5]/$idMark), 2));
But it’s like I said, I do not know if it is the best way, because I do not know what the purpose of the code.
If you are working with percentage (which is not certain due to variable $ratings[5]
) you could just do so:
round(($ratings[5] / $idMark) * 100);
And I used str_replace, it worked :D, thank you very much
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
Is that some kind of factor? You can’t just multiply by 100 and round?
– utluiz
@utluiz Ta ta already solved!
– William Alvares
Okay, I saw that you accepted the answer and got the expected result. But using string manipulation over numerical values sounds like a beautiful gambit to me. What if the result of the split is something like
1.23
?– utluiz
@utluiz ai vai meio q ser inutil o str_replace e continuar normal neh..?
– William Alvares
Yeah, and that’s called inconsistency.
– utluiz
@utluiz was what I said clearly in the answer, as it is not possible to be sure which objective of the code has no way to affirm a better path, since to catch the value after the point number already sounds strange by itself.
– Guilherme Nascimento
is an evaluation system, for example if you have 20,000,000 votes on 5 stars and the total votes on all stars is 35,000,000 will give 0.57 and you will get that 0. always q need to withdraw to put the value="57" in the bar Progress
– William Alvares