Fix amounts from showing scientific notation

Very small amounts were showing scientific notation numbers when
dispaying the total amount of tips on a meme or user or on the
leaderboard. This should fix that.

There may be a cleaner way to do this but this gets the job done.
This commit is contained in:
dev 2021-12-10 15:20:05 -06:00
parent 9cfea79309
commit c5141e10e0
2 changed files with 14 additions and 2 deletions

View File

@ -42,7 +42,13 @@ class Meme extends Model
public function getMemeTipsTotalAttribute()
{
return $this->tips->where('is_deposit', 1)->sum('amount_formatted');
if ($this->tips->where('is_deposit', 1)->sum('amount_formatted')) {
return rtrim(sprintf('%.8f',floatval(
$this->tips->where('is_deposit', 1)->sum('amount_formatted')
)),'0');
} else {
return 0;
}
}
public function getImageUrlAttribute()

View File

@ -66,7 +66,13 @@ class User extends Authenticatable
public function getTipsTotalAttribute()
{
return $this->tips->where('is_deposit', 1)->sum('amount_formatted');
if ($this->tips->where('is_deposit', 1)->sum('amount_formatted')) {
return rtrim(sprintf('%.8f',floatval(
$this->tips->where('is_deposit', 1)->sum('amount_formatted')
)),'0');
} else {
return 0;
}
}
}