LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

float to integer


Ravens Fan wrote:

Try your code with a negative number and see if it makes sense.


Great catch!  Knew I had to hurry with you guys involved...Smiley Wink 
 Now it works.  OP wants to deal with FP representations and Banker's rounding, so I'll let you guys handle it.

 

0 Kudos
Message 11 of 25
(2,199 Views)

said:Here's a solution that should work for:    Any number,   Any base (decimal is base 10),    Any precision .

 

 

Sorry, this has gotten way out of hand for my application and

way too complicated for my application.  I've got my answer

that fits my data range.  


 

 

0 Kudos
Message 12 of 25
(2,195 Views)

PointOnePa wrote:

said:Here's a solution that should work for:    Any number,   Any base (decimal is base 10),    Any precision .

 

 

Sorry, this has gotten way out of hand for my application and

way too complicated for my application.  I've got my answer

that fits my data range.  


 

 


Yes, I understand that, but is your solution flexible?

 

However here is a negative proof solution:

 

BaseFix.png

 

It is the first time I ever used the Sign functionality.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 13 of 25
(2,192 Views)

Here's yet another alternative for 3 digits (-99.9..99.9). If you don't need negative, simply delete the irrelevant parts. 🙂

 

This code assumes that the input is in the correct range, else you would need to also coerce the absolute integer to 0..999.

 

Message Edited by altenbach on 08-16-2009 12:52 PM
0 Kudos
Message 14 of 25
(2,189 Views)

altenbach said: Here's yet another alternative for 3 digits

 

 

Yeah, this is what I ended up doing as described in a previous post, except without the for-loop,

which is a much cleaner implementation that what I posted in Float_to_Int3.gif .    Thanks.

0 Kudos
Message 15 of 25
(2,176 Views)

@TonP wrote:

 

 


 

However here is a negative proof solution:

 

Ton


Kudos for (s)he who finds the bug. (without re-coding it).

 

Ton

Message Edited by TonP on 16-08-2009 10:08 PM
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 16 of 25
(2,165 Views)

TonP wrote:

Kudos for (s)he who finds the bug. (without re-coding it).

 

 

The fact it suffers from the floating point issues, I don't consider a bug.  Is it a feature that all of the digits will be negative if the number is < 0? 

 

0 Kudos
Message 17 of 25
(2,155 Views)

It should not suffer from floating point issues, could you describe this a little bit more?

 

 

Is it a feature that all of the digits will be negative if the number is < 0? 

Yes, consider  '-13', that means -1 times 10 and -3 times 1. 

It is also valid to negate the units.

 

Ton

 

 

 

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 18 of 25
(2,139 Views)

Sorry if I am mistaken, but since I didn't code it you'll have to tell me.  I assume if you put in for example 1.4, you'll get 1.399 or something similar.  Not a bug, just a fact of life in floating point math.

 

All digits being negative is certainly fine, just not sure if it was the effect you were shooting for. 

Message Edited by Darin.K on 08-16-2009 04:55 PM
Message Edited by Darin.K on 08-16-2009 05:03 PM
0 Kudos
Message 19 of 25
(2,132 Views)

Zero sets all units to infinity.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 20 of 25
(2,097 Views)