number format

Discuss all problems you have with Servoy here. It might help to mention the Servoy version and Operating System version you are using

number format

Postby robysimo09 » Wed Mar 20, 2013 6:31 pm

Hello

I have a serious problem with number format.
I have a value like 290,955.
I need to format the number to 290,96 with 2 decimal and return a string; I use utils.numberFormat( 290.955, '###0.00' ).
There are strange situations
Below the results:

=>utils.numberFormat( 290.105, '###0.00' )
"290,10" ERROR

=>utils.numberFormat( 290.115, '###0.00' )
"290,12" CORRECT

=>utils.numberFormat( 290.125, '###0.00' )
"290,12" ERROR

=>utils.numberFormat( 290.135, '###0.00' )
"290,14" CORRECT

=>utils.numberFormat( 290.145, '###0.00' )
"290,14" ERROR

=>utils.numberFormat( 290.155, '###0.00' )
"290,16" CORRECT

=>utils.numberFormat( 290.165, '###0.00' )
"290,16" ERROR

=>utils.numberFormat( 290.175, '###0.00' )
"290,18" CORRECT

=>utils.numberFormat( 290.185, '###0.00' )
"290,18" ERROR

=>utils.numberFormat( 290.195, '###0.00' )
"290,20" CORRECT



I have already tried with toFixed method: 290.955.toFixed(2)
Below the results:

=>290.105.toFixed( 2 )
"290.11" CORRECT

=>290.115.toFixed( 2 )
"290.12" CORRECT

=>290.125.toFixed( 2 )
"290.13" CORRECT

=>290.135.toFixed( 2 )
"290.13" ERROR

=>290.145.toFixed( 2 )
"290.14" ERROR

=>290.155.toFixed( 2 )
"290.15" ERROR

=>290.165.toFixed( 2 )
"290.17" CORRECT

=>290.175.toFixed( 2 )
"290.18" CORRECT

=>290.185.toFixed( 2 )
"290.19" CORRECT

=>290.195.toFixed( 2 )
"290.19" ERROR

How can I solve this? Is this a bug?
I use servoy 5.2.15
Thank you very much!
Roberto
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am

Re: number format

Postby Manolo_Etec » Wed Mar 20, 2013 6:43 pm

Hi Roberto


I used this.

utils.numberFormat( Math.round(x*100)/100, '###0.00' )
Manuel López
Etec Programación SL
manuel@etecsoft.com
http://www.etecsoft.com
User avatar
Manolo_Etec
 
Posts: 66
Joined: Fri Sep 12, 2008 3:58 pm

Re: number format

Postby Andrei Costescu » Thu Mar 21, 2013 11:26 am

utils.numberFormat() works as you want it here (round-half-up) starting with 6.1. (SVY-135)

The native JS call Number.toFixed() works exactly as in Servoy for all (4) browsers that I tested except IE. IE will round as you expect it to. I checked the ECMA script specs. - there is nothing mentioned about what kind of rounding should be used. So .toFixed behaves according to the standard in all cases. (IE/Rhino/other browsers)
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm

Re: number format

Postby robysimo09 » Wed Sep 11, 2013 3:17 pm

Hello

is possible to add the new fix SVY-135 in servoy 5.2.x? it's fixed for servoy 6.1
It's very important for our accounting!!!

Thank you very much!
Bye bye from Italy

Roberto
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am

Re: number format

Postby juan.cristobo » Wed Sep 11, 2013 4:48 pm

BW, I'm migrating my apps to Servoy 7.2, I receive this error message:

Code: Select all
The method numberFormat() from the type JSUtils is deprecated


:shock: :shock:
Juan
Madrid (Spain)

Servoy 7.4.x - MySQL / SQL Server 2008-2016
Windows 10 Pro
juan.cristobo
 
Posts: 186
Joined: Thu Apr 19, 2012 9:12 am

Re: number format

Postby Harjo » Thu Sep 12, 2013 9:50 am

Not the whole numberFormat is deprecated, but the way you use it know is deprecated.
So closely look at the (count of) arguments and if the jsdoc of thos properties are right!
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: number format

Postby robysimo09 » Thu Sep 12, 2013 11:57 am

Hello

no one from servoy? I need this fix on servoy 5.2.x!! :cry:

Bye
Roberto
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am

Re: number format

Postby Harjo » Thu Sep 12, 2013 1:30 pm

Please post your questions/comment in the support system, there it will be seen by the Servoy Team.
Beside your question, of fixing this in Servoy 5.x, what is the reason you can't upgrade to 6 or 7?
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: number format

Postby robysimo09 » Thu Sep 12, 2013 2:11 pm

Thanks Harjo for reply.

I cannot upgrade to servoy 6 or 7 because now we must to finish our software. But a part of our new software is already used by many customers and we have many errors in invoices and accounting. :(

I will open a case now.

Bye
Roberto
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am

Re: number format

Postby lwjwillemsen » Thu Sep 12, 2013 2:48 pm

My advice to Roberto :

Keep numerical computations like round, floor, ceiling in the numerical 'world'...

so :
var a = 13.496
var b = ourOwnRoundFunction(a, 2) // round on 2 decimals
utils.numberformat(b, '###0.00')

Regards,
Lambert Willemsen
Vision Development BV
lwjwillemsen
 
Posts: 680
Joined: Sat Mar 14, 2009 5:39 pm
Location: The Netherlands

Re: number format

Postby robysimo09 » Fri Sep 13, 2013 10:32 am

Thank you for answer

Can you show me an example of "ourOwnRoundFunction"

Thank you very much!
Roberto
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am

Re: number format

Postby sovanm » Fri Sep 13, 2013 11:03 am

Hi,

You can try out this function to round your number to any precision.

Code: Select all
function ourOwnRoundFunction(value, places) {

   var multiplier = Math.pow(10, places);
   return (Math.round(value * multiplier) / multiplier);
}


Then you can use this to show the number as suggested

Code: Select all
var a = 13.496
var b = ourOwnRoundFunction(a, 2) // returns 13.5
utils.numberformat(b, '###0.00')



Thanks,
Last edited by sovanm on Fri Sep 13, 2013 11:55 am, edited 1 time in total.
sovanm
 
Posts: 99
Joined: Fri Oct 28, 2011 1:55 pm
Location: Bhubaneswar, India

Re: number format

Postby lwjwillemsen » Fri Sep 13, 2013 11:50 am

Ok, that's the same one we use...
Lambert Willemsen
Vision Development BV
lwjwillemsen
 
Posts: 680
Joined: Sat Mar 14, 2009 5:39 pm
Location: The Netherlands

Re: number format

Postby robysimo09 » Fri Sep 13, 2013 12:03 pm

Thank you

I tried but.... below an example:

utils.numberFormat( Math.round(290.155 * Math.pow(10, 2)) / Math.pow(10, 2), '###0.00' ) = "290,15"
NOT CORRECT. The correct value is "290,16"


Thank you
Roberto
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am

Re: number format

Postby lwjwillemsen » Fri Sep 13, 2013 1:28 pm

Welcome to javascript precision :

Math.round(29015.5) gives 29016
Math.round(290.155 * 100) gives 29015 !

So do the multiply with the Math.pow(10,2) into a variable beforehand for better precision...
Lambert Willemsen
Vision Development BV
lwjwillemsen
 
Posts: 680
Joined: Sat Mar 14, 2009 5:39 pm
Location: The Netherlands

Next

Return to Discuss possible Issues and Bugs

Who is online

Users browsing this forum: Google [Bot] and 9 guests