query re. displaying floats


    Sep 28 2007 | 5:44 pm
    hi
    i have an interface built wth lcd on which i want to display float values which i've rounded to 2 decimal places - ie, 0.777000 becomes 0.780000, but i don't want the extra zeros - i only want to display 0.78. anyone any idea on how i do this?
    thanks

    • Sep 28 2007 | 6:06 pm
      Quote: robin wrote on Fri, 28 September 2007 10:44 ---------------------------------------------------- > hi > > i have an interface built wth lcd on which i want to display float values which i've rounded to 2 decimal places - ie, 0.777000 becomes 0.780000, but i don't want the extra zeros - i only want to display 0.78. anyone any idea on how i do this? > > thanks ----------------------------------------------------
      [sprintf %.2f]
      Make sure that you keep the output of the sprintf as a symbol. Max will try to convert it to a float, if possible, and you'll loose your formatting.
      mz
    • Sep 28 2007 | 6:09 pm
      brilliant...i'd just turned to sprintf, but hadn't got so far as that.
      thanks a lot
    • Sep 28 2007 | 6:13 pm
      uh...actually, that doesn't appear to work. it still gives 4 decimal places - if i feed it 0.12 i get 0.1200 out, even as a symbol
    • Sep 28 2007 | 6:43 pm
      Works here...
      [sprintf symout %.2f]
    • Sep 28 2007 | 6:46 pm
      Quote: robin wrote on Fri, 28 September 2007 11:13 ---------------------------------------------------- > uh...actually, that doesn't appear to work. it still gives 4 decimal places - if i feed it 0.12 i get 0.1200 out, even as a symbol ----------------------------------------------------
      Max is aggressive about converting... looks like LCD is changing it back to a float. If you add a blank character at the end it should work.
      Try:
    • Sep 28 2007 | 6:57 pm
      On 28 sept. 07, at 20:46, mzed wrote:
      > > Quote: robin wrote on Fri, 28 September 2007 11:13 > ---------------------------------------------------- >> uh...actually, that doesn't appear to work. it still gives 4 >> decimal places - if i feed it 0.12 i get 0.1200 out, even as a symbol > ---------------------------------------------------- > > Max is aggressive about converting... looks like LCD is changing it > back to a float. If you add a blank character at the end it should > work.
      It's because you need to output a symbol from sprintf, and then prepend by "write".
      ej
    • Sep 28 2007 | 7:12 pm
      lovely. thanks guys.