M Mark Stuart Well-Known Member Licensed User Longtime User Sep 29, 2017 #1 Hi all, I'm formatting numbers from a SQLite table where the stored data type is REAL. Some of the records (ItemPrice field) have a 0 (zero) value in them. I'd like to use the formatting as such: Code: Copy Dim Price As Double = 0 Price = NumberFormat(cr.GetDouble("ItemPrice"),0,2) For those records with a value greater than zero, it has 2 decimal places, but when the value is 0 (zero), there is no formatting. It displays as 0. I'd expect 0.00. Anyone know why this is and how to correctly format zeros? Thanx, Mark S. Last edited: Sep 29, 2017
Hi all, I'm formatting numbers from a SQLite table where the stored data type is REAL. Some of the records (ItemPrice field) have a 0 (zero) value in them. I'd like to use the formatting as such: Code: Copy Dim Price As Double = 0 Price = NumberFormat(cr.GetDouble("ItemPrice"),0,2) For those records with a value greater than zero, it has 2 decimal places, but when the value is 0 (zero), there is no formatting. It displays as 0. I'd expect 0.00. Anyone know why this is and how to correctly format zeros? Thanx, Mark S.
fixit30 Active Member Licensed User Longtime User Sep 29, 2017 #2 NumberFormat returns a String, therefore your code should be: Code: Copy Dim Price As String Price = NumberFormat(cr.GetDouble("ItemPrice"),0,2) Upvote 0
NumberFormat returns a String, therefore your code should be: Code: Copy Dim Price As String Price = NumberFormat(cr.GetDouble("ItemPrice"),0,2)
klaus Expert Licensed User Longtime User Sep 29, 2017 #3 NumberFormat returns a String! So you should set: Dim Price As String In your case the String returned by the NumberFormat function is converted into a Double! You may also consider NumberFormat2 where you can define MinimumFractions and MaximumFractions. Upvote 0
NumberFormat returns a String! So you should set: Dim Price As String In your case the String returned by the NumberFormat function is converted into a Double! You may also consider NumberFormat2 where you can define MinimumFractions and MaximumFractions.
M Mark Stuart Well-Known Member Licensed User Longtime User Oct 2, 2017 #4 This worked in formatting the 0 value to display 0.00: (thanx guys) Code: Copy Dim Price as String = "" Price = NumberFormat2(cr.GetDouble("ItemPrice"),1,2,2,False) The above I'm now using. This did not format the 0 value to a display of 0.00: Code: Copy Dim Price as String = "" Price = NumberFormat(cr.GetDouble("ItemPrice"),1,2) The above function arguments are misleading as I'd expect the display format to be a minimum of 1 placing in the integer position (in this case would be a 0) and a minimum of 2 placings in the decimal positions - 00 Is this a bug? Seems to me it may be, or very misleading/confusing. If it worked, I wouldn't be submitting to the forum for answers. I think it needs to be looked at by the products developers. Thanx, Mark S. Upvote 0
This worked in formatting the 0 value to display 0.00: (thanx guys) Code: Copy Dim Price as String = "" Price = NumberFormat2(cr.GetDouble("ItemPrice"),1,2,2,False) The above I'm now using. This did not format the 0 value to a display of 0.00: Code: Copy Dim Price as String = "" Price = NumberFormat(cr.GetDouble("ItemPrice"),1,2) The above function arguments are misleading as I'd expect the display format to be a minimum of 1 placing in the integer position (in this case would be a 0) and a minimum of 2 placings in the decimal positions - 00 Is this a bug? Seems to me it may be, or very misleading/confusing. If it worked, I wouldn't be submitting to the forum for answers. I think it needs to be looked at by the products developers. Thanx, Mark S.
OliverA Expert Licensed User Longtime User Oct 2, 2017 #5 It's not a bug. See the documentation on NumberFormat (here). The third parameter is for "maximum" number of fractions, it says nothing about minimum. All 0's are left off. As @klaus mentions, you need to use NumberFormat2. @klaus has this answered in another thread here: https://www.b4x.com/android/forum/t...at2-not-formating-decimals.39354/#post-378164 Upvote 0
It's not a bug. See the documentation on NumberFormat (here). The third parameter is for "maximum" number of fractions, it says nothing about minimum. All 0's are left off. As @klaus mentions, you need to use NumberFormat2. @klaus has this answered in another thread here: https://www.b4x.com/android/forum/t...at2-not-formating-decimals.39354/#post-378164