# How to format data type single for LCDX 4x20 display with two decimal places?

Started by March 13, 2011
I have been trying to find a way to format data type single data so that when I write it to the LCDX 4x20 LCD, only two decimal places are displayed. One method I've considered is to multiply the value by 10 or 100, then convert to Integer, convert back to single, then divide by 10 or 100 before displaying. This method works for all values except 0.60. When the value is 0.60 this method produces 0.6000001 when written to the display over running the next line with part of the data. I have noticed in the Language_Reference.pdf there is reference to using Fix, FixB, FixI and FixL to convert data types. Can someone refer me to any documentation which shows how to use these, and maybe a simple way to format data written to the LCD? Thanks.

Hi,

Fmt is what you want. Here is an example for the docs:
Public Sub Main()

Dim X As Single

Do

' Display random number between 0 and 100.

X = Rnd * 100.0

Debug.Print Fmt(X, 2) ' Only display 2 digits past the decimal point

Call Delay(0.5)

Loop

End Sub

On Sun, Mar 13, 2011 at 1:04 PM, ronoutous wrote:

> I have been trying to find a way to format data type single data so that
> when I write it to the LCDX 4x20 LCD, only two decimal places are displayed.
> One method I've considered is to multiply the value by 10 or 100, then
> convert to Integer, convert back to single, then divide by 10 or 100 before
> displaying. This method works for all values except 0.60. When the value is
> 0.60 this method produces 0.6000001 when written to the display over running
> the next line with part of the data. I have noticed in the
> Language_Reference.pdf there is reference to using Fix, FixB, FixI and FixL
> to convert data types. Can someone refer me to any documentation which shows
> how to use these, and maybe a simple way to format data written to the LCD?
> Thanks.
>