Announcement

Collapse
No announcement yet.

Can i get a little help?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • telco
    replied
    Thanks Bio.. now i got it..
    About my request last year yes, but its focusing on 100% of the volume not the 255..

    Again.. many thanks..

    Leave a comment:


  • BioHazard
    replied
    ... And so, using first option Math.Round() on a timer might look something like this:
    Attached Files

    Leave a comment:


  • BioHazard
    replied
    Is basic math issue, here. When working with 0-255 volume-range, percentage will never be whole integer. Always 1+ decimal places. So, we can employ Math.Round or Floating-Point-Integer Pattern to round up/down to closest whole number. So, some options we can do:
    Code:
    [COLOR=#008000][I]-- #########################################################################
    -- NOTES:
    -- Whereby nVol = variable for for retrieved volume-number (eg. 0-255)
    -- Whereby pVol = variable for for volume-number expressed as percentage(%)
    -- #########################################################################[/I][/COLOR]
    
    [I][COLOR=#008000]-- Option 1: Use Math.Round command (rounds up/down to closest whole number, if set for '0' decimal places)[/COLOR][/I]
    nVol = 253;
    pVol = (nVol / 255) * 100;
    pVol_rounded = Math.Round(pVol , 0);
    Label.SetText("Vol", pVol_rounded .. "%");
    
    
    [I][COLOR=#008000]-- Option 2: Use Floating-Point-Integer Pattern (rounds up/down to closest whole number, if set for '0' decimal places)[/COLOR][/I]
    nVol = 253;
    pVol = (nVol / 255) * 100;
    pVol_rounded = string.format("%.0f", pVol);
    Label.SetText("Vol", pVol_rounded .. "%");
    
    
    [I][COLOR=#008000]-- Option 3: Integrate EITHER method into single-argument function[/COLOR][/I]
    nVol = 253; 
    pVol = (nVol / 255) * 100;
    [COLOR=#0000FF]function[/COLOR] pVol_rounded (pVol)
        [COLOR=#0000FF]return[/COLOR] Math.Round(pVol, 0);
    [COLOR=#0000FF]end[/COLOR]
    Label.SetText("Vol", pVol_rounded (pVol) .. "%");
    
    [I][COLOR=#008000]-- or[/COLOR][/I]
    
    nVol = 253; 
    pVol = (nVol / 255) * 100;
    [COLOR=#0000FF]function[/COLOR] pVol_rounded (pVol)
        [COLOR=#0000FF]return[/COLOR] string.format("%.0f", pVol);
    [COLOR=#0000FF]end[/COLOR]
    Label.SetText("Vol", pVol_rounded (pVol) .. "%");
    There are other options, too.
    Google is your bud with this one, bud!.
    .
    PS.
    Noticed another thread where you were working on audio-project, last year. Not sure whether this request is at all related. But in any event, attached are some APZ examples demonstrating audio-volume display & tracking. Might be of some interest / relevance. (Wrote these quite a few years back - under different incarnation - but they're all up-to-date now - for v8.5 / Lua5.1).
    Attached Files

    Leave a comment:


  • telco
    started a topic Can i get a little help?

    Can i get a little help?

    I have a audio incorporate on my apps. I know the max volume of Audio is 255 and i do this

    nVol = nVolume / 2.55;

    Label.SetText("Vol", nVol.."%");


    The problem is the result below 100 is 99.12242543645%


    how can i make it fixed in number?

    Example: 100-99-98-97 >>>>>
Working...
X