NAN when dividing 0 by 0

BvstedCrew

I made a Poll Voting with an Result Page. But wenn there are no votes it gives me an NAN Calc Error.

Code:

<div class="progress-bar" style="background-color: #38b673; width:<?= @(($poll_answer['votes'] / $total_votes) * 100)?>%">
<?= @round(($poll_answer['votes'] / $total_votes) * 100) ?>%
</div>

I tried different things, but nothing works.

Maybe anyone knows how to fix.

nice_dev

You can just use max() function to overcome divide by 0 issue.

<?php echo round(($poll_answer['votes'] / max(1,$total_votes)) * 100); ?>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Power BI returning value >0 for when dividing by 0

PHP dividing by 10, adding +1 when result is greater than .0

Error message for dividing by zero when variable in 0 is = 1

Dividing 2 numbers returns 0

Dividing long by long returns 0

Protect calculator from dividing by 0

Matlab: 0 < NaN = 0

jQuery Knob displays NaN when value is 0

Receiving NaN when passing argument "0" to function

Preventing NaN when dividing zero with value

I cannot produce an error message with division when dividing by 0 (Javascript Calculator)

Dividing by 0 is a compiler error or a runtime error

How is dividing by 0 not a 'divide by zero' exception?

Dividing a number in loop until it satisfies a condition = 0

Dividing by 0 error / Sorry my sentences are in PT

Xcode 9 / iOS 11 "CALayer bounds contains NaN: [nan 0; nan 0]" when popping view controller with nested UINavigationController and UITabBarController

Sum of dataframes : treating NaN as 0 when summed with other values, but returning NaN where all summed elements are NaN

Convert NaN to 0 in javascript

replacing float 0 with NaN

Avoid NaN and Inf when dividing in R (using within formula)

invalid literal for int() with base 10: 'nan' when trying to replace 0 in NaN

How can I make NaN values sum to NaN rather than 0 when using df.resample?

Multiply NaN or Inf with 0 and get 0

when I run my code it executes 0 0 0 0 0 0 0 0 0?

Netlogo How can I avoid the "dividing by 0" error during the dividing process compiling with Behavior space?

Dividing two integers in Java gives me 0 or 100?

x86 Assembly (NASM): Floating Point Exception, not dividing by 0?

Dividing a list by another with some "0"s in the denominator list

Dividing two integers results 0, while I should get 1

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  7. 7

    Do Idle Snowflake Connections Use Cloud Services Credits?

  8. 8

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  9. 9

    Binding element 'string' implicitly has an 'any' type

  10. 10

    BigQuery - concatenate ignoring NULL

  11. 11

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  12. 12

    In Skype, how to block "User requests your details"?

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Pandas - check if dataframe has negative value in any column

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Generate random UUIDv4 with Elm

  17. 17

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  18. 18

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  19. 19

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  20. 20

    EXCEL: Find sum of values in one column with criteria from other column

  21. 21

    How to use merge windows unallocated space into Ubuntu using GParted?

HotTag

Archive