How to map moon phase number + "lunation" to moon phase name? I am querying an API (weatherbit) which returns a moon phase number which looks like this:
0.9594168
For the 16 days I look at the numbers vary from 0.006 to 0.99.
I have 8 &quot;moon phase&quot; icons for the full, crescent, gibbous, etc. phases.  Filenames are the phase names.
How can I map the moon phase number to the phase names so I can use images with those names appropriately.
Final Update: Use moon_phase_lunation (instead of moon phase number) only
Here is the final js-react code which seems to be working well so far:
import React from 'react';
const Moon = ( data ) =&gt; {
  const lunation = Number(data.moon_phase_lunation);
  let imageToUse;
  if (lunation &lt;= .06) imageToUse = 'new';
  if (lunation &gt; 0.06 &amp;&amp; lunation &lt;= .19) imageToUse = 'waxing_crescent';
  if (lunation &gt; 0.19 &amp;&amp; lunation &lt;= .31) imageToUse = 'third_quarter';
  if (lunation &gt; 0.31 &amp;&amp; lunation &lt;= .44) imageToUse = 'waxing_gibbous';
  if (lunation &gt; 0.44 &amp;&amp; lunation &lt;= .56) imageToUse = 'full';
  if (lunation &gt; 0.56 &amp;&amp; lunation &lt;= .69) imageToUse = 'waning_gibbous';
  if (lunation &gt; 0.69 &amp;&amp; lunation &lt;= .81) imageToUse = 'first_quarter';
  if (lunation &gt; 0.81 &amp;&amp; lunation &lt;= .94) imageToUse = 'waning_crescent';
  if (lunation &gt; 0.94 ) imageToUse = 'new';
  const imageURL = `/moonIcons/${imageToUse}.png`;
  return (
    &lt;&gt;
      &lt;img src= { imageURL } width=&quot;20px&quot; height=&quot;20px&quot; /&gt;
    &lt;/&gt;
  );
};

export default Moon;
The WeatherBit 16-day forecast documentation gives these output field descriptions:


moon_phase: Moon phase illumination fraction (0-1)
moon_phase_lunation: Moon lunation fraction (0 = New moon, 0.50 = Full Moon, 0.75 = Last quarter moon)


The illuminated fraction doesn't help you distinguish waxing and waning phases, so moon_phase_lunation is the value to use.
One possible mapping is:
0.0  0.06  0.19  0.31  0.44  0.56  0.69  0.81  0.94  1.0