Normal Topic floating comma bug (Read 1549 times)
wase
Junior Member
**
Offline


Always looking for a good
code

Posts: 57
Location: Austria
Joined: Jun 22nd, 2004
floating comma bug
Mar 4th, 2006 at 10:41am
Print Post Print Post  
hi

i have a problem with a number LE

when i put two LE`s on a  form the first is a number LE (name n1) and the second is a text LE (name t1)

following code is programmed in element exit of t1

Code
Select All
t1 = @str(@decimals(n1, 2))
 



when type in n1 the following number 17,24 then i get in the LE  t1 17,23
is it possible that there is a bug in the floating comma operation or something like that

when i use @decimals(n1, 4) i get 17,2399

this happens in severel cases e.g. 18,13; 18,38....

could you help please

- sebastian
  
Back to top
ICQ ICQ  
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: floating comma bug
Reply #1 - Mar 4th, 2006 at 4:35pm
Print Post Print Post  
There is a known bug in association with rounding and @decimals. I think there might be a hotfix for that, as well as a work-around posted here by Carl Underwood. Contact tech support for the hotfix.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: floating comma bug
Reply #2 - Mar 5th, 2006 at 1:38am
Print Post Print Post  
I created these two custom functions to use until the built-in functions are fixed, which should be in the next Sesame release. There's an article that I wrote for Inside Sesame (June 2005, Page 17) that covers the rounding problem and the reason for it.

Since you are using commas instead of periods for the decimal symbol, you will need change the periods to commas at the appropriate places within the code.

Let me know how you make out.

Code
Select All
//########## Begin Custom Decimals Function ##########
// @cuDecimals(V, P)
// Parameters: V as Double, P as Integer
// Returns: String

Function @cuDecimals(Value as double, Places as int) as string

var vStr as string = @Str(Value)

if @Instr(vStr, ".") > 0
	vStr = vStr + "000000"
else
	vStr = vStr + ".000000"

vStr = @Del(vStr, @Instr(vStr, ".") + Places + 1, 10)

Return vStr

End Function
//########## End Custom Decimals Function ##########


//########## Begin Custom Rounding Function ##########
// @cuRND(V, P)
// Parameters: V as Double, P as Integer
// Returns: Double

// Rounds off the value of V to P decimal places. Unlike the regular @RND function, the value
// of P must be a positive number, meaning that it is only designed to round to whole numbers
// or to tenths, hundredths, thousandths, etc. - not to the nearest tens, hundreds, etc.

Function @cuRND(Value as double, Places as int) as double

var vNeg as int		//Used to handle Negatives properly
var vStr as string

if Value < 0
	vNeg = -1
else
	vNeg = 1

vStr = @Str(@Abs(Value))

if @Instr(vStr, ".") > 0	//Protects whole numbers when rounding to zero places
	{
	if @Mid(vStr, @Instr(vStr, ".") + Places + 1, 1) >= 5
		vStr = @Str( @TN(vStr) + (1 / @Exp(10, Places)) )
	vStr = @Del(vStr, @Instr(vStr, ".") + Places + 1, 10)
	}

vStr = @Str(@TN(vStr) * vNeg)

Return @TN(vStr)

End Function
//########## End Custom Rounding Function ##########
 

  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: floating comma bug
Reply #3 - Sep 18th, 2006 at 4:22pm
Print Post Print Post  
Is @cuRND still the best way to handle the money rounding issue or has this been addressed in 1.1.4?
  

**
Captain Infinity
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: floating comma bug
Reply #4 - Sep 18th, 2006 at 4:39pm
Print Post Print Post  
Version 1.1.4 contains the same fix for @Round() that the 1.1.3 Hotfix contained.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: floating comma bug
Reply #5 - Sep 18th, 2006 at 4:44pm
Print Post Print Post  
Thank you.  If I understand you, @cuRND is no longer needed?
  

**
Captain Infinity
Back to top
IP Logged