How to stop Format displaying period?

I want to display numbers in a listBox using the Format(myNumber, “###,###,###,###,##0.##”) command. Everything works fine except when the value to the right of the decimal point is zero, then 100 appears as ‘100.’ i.e. with a period at the end. How can I suppress the period without an additional IF command?

AFAIK, you can’t :frowning:

What about checking whether your number is round?
E.g.: if round(number)=number then
//format without the period
else
//format with the period
end if

Instead of “###,###,###,###,##0.##” use “###,###,###,###,##0.00”.

That way all the numbers in the column will be aligned.

Hi David,

I had the same problem a while back, this is the method I ended up using:

Private Function X3_Str(d As Double) As String
  if (d \\ 1) = d then // whole number?
    return Str(d, "-0")
  else
    return Str(d, "-0.#######")
  end if
End Function

For more information on how I arrived at this method, hava a look at this conversation…

https://forum.xojo.com/4437-str-converts-to-scientific-notation

Would this work with double precision?

Not sure what you’re referring to Arnaud?

The function rounds to 7 decimal places, if that answers your question?

return if(floor(d)=d,format(d,"-0",format(d,"-0.0####"))

Thanks to everybody who replied. I want a solution because I think a number ending in ‘.’ or ‘.0’ or ‘.00’ is ugly and I was hoping for a simple replacement Format string! My workaround is to check if the string ends in a ‘.’ and if so, I remove it.

I like Dave S’ one line solution a lot.