floating-point number

  • Thread starter floating-point number convert
  • Start date
F

floating-point number convert

Hello,

I have a problem with convert a larg floating-point number in a short.

For Example: I have 2,1515151 and i'd like to create 2,15.
I can do this with string but not with Integer.
Can sombody help me?
 
J

John

floating-point number convert <floating-point number
Hello,

I have a problem with convert a larg floating-point number in a short.

For Example: I have 2,1515151 and i'd like to create 2,15.
I can do this with string but not with Integer.
Can sombody help me?

convert,
Well, you can't do it with an integer because a floating point number is
not an integer. The only thing you can do is to change the presentation
of the number, not the value itself. If the number is 2.1515151, then it
will be stored that way (or to even greater precision) depending on how
the number is declared (e.g. double, single, etc.).

The simplest way to display it is with a Format Function:
Format (2.1515151, "#.00")
The Format Function will round the value appropriately. If you don't
care about rounding and only want to truncate, then you could use the
Mid Function:
csng(mid(2.15615,1,4))

John
Project MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top