Illegal Number Format Exception in Java - jlabel

I have this code, which pulls in a double value from an external method call, converts it into a String and then displays it in a JLabel.
My problem is that sometimes the value might display: 1.95000000000000001, and I want to reduce that to 1.95. When I run the application, it prints: Illegal Number Format Exception. Any help would be greatly appreciated.
if (query.equals("BREAD602")) {
callMethod.findBread();
totalPrice = Double.toString(callMethod.totalPriceMethod());
totalPriceLabel.setText(String.format("%.2f", " Totalprice to pay: £" + totalPrice));

Use this
totalPriceLabel.setText(String.format("Totalprice to pay: £%.2f", totalPrice));

Related

Can nested LookUp be done?

Hi again dear stackoverflowers!
I have one column in Sharepoint for an ID number (say that the number is 29) and another column that for that ID holds different subIDs (29.1, 29.2, 29.3, etc.).
What I need is that my PowerApp looks up into the Sharepoint list and takes the maximum subID number associated with the ID given, and automatically sums 0.1, because I do not want people to introduce two equal subIDs.
I'll give you the formula I tried (but the problem is that StartsWith is for text and Max is for numbers), so if you have any ideas about how can it be solved or you have any function that works with both text and numbers I would really appreciate it:
LookUp(my_list.'Prueba', StartsWith('Prueba' , DataCardValue9_2.Text), Max('Prueba')+0.1)
Another thing I tried was to nest LookUp functions, but that did not work either, do you know if that can be done?
LookUp(my_list, Prueba = DataCardValue9_2.Text + 0.3 , Max(Prueba) + 0.1) & LookUp(my_list, Prueba = DataCardValue9_2.Text + 0.2 , Max(Prueba) + 0.1) & LookUp(my_list, Prueba = DataCardValue9_2.Text + 0.1 , Max(Prueba) + 0.1)
Thank you very much for your time and help.
You must convert your column to a number datatype. Value() function for number.
Please do check this link: https://learn.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-value

invalid input syntax for type numeric: " "

I'm getting this message in Redshift: invalid input syntax for type numeric: " " , even after trying to implement the advice found in SO.
I am trying to convert text to number.
In my inner join, I try to make sure that the text being processed is first converted to null when there is an empty string, like so:
nullif(trim(atl.original_pricev::text),'') as original_price
... I noticed from a related post on coalesce that you have to convert the value to text before you can try and nullif it.
Then in the outer join, I test to see that there's a limited set of acceptable characters and if this test is met I try to do the to_number conversion:
,case
when regexp_instr(trim(atl.original_price),'[^0-9.$,]')=0
then to_number(atl.original_price,'FM999999999D00')
else null
end as original_price2
At this point I get the above error and unfortunately I can't see the details in datagrip to get the offending value.
So my questions are:
I notice that there is an empty space in my error message:
invalid input syntax for type numeric: " " . Does this error have the exact same meaning as
invalid input syntax for type numeric:'' which is what I see in similar posts??
Of course: what am I doing wrong?
Thanks!
It's hard to know for sure without some data and the complete code to try and reproduce the example, but as some have mentioned in the comments the most likely cause is the to_number() function you are using.
In the earlier code fragment you are converting original_price to text (string) and then substituting an empty string ('') if the value is NULL. Calling the to_number() function on an empty string will give you the error described.
Without the full SQL statement it's not clear why you're putting the nullif() function around the original_price in the "inner join" or how whether the CASE statement is really in an outer join clause or one of the columns returned by the query. However you could perhaps alter the nullif() to substitute a value that can be converted to a number e.g. '0.00' instead of ''.
Sorry I couldn't share real data. I spent the weekend testing small sets to try and trap the error. I found that the error was caused by the input string having no numbers, which is permitted by my regex filter:
when regexp_instr(trim(atl.original_price),'[^0-9.$,]') .
I wrongly expected that a non numeric string like "$" would evaluate to NULL and then the to_number function would = NULL . But from experimenting it seems that it needs at least one number somewhere in the string. Otherwise it reduces the string argument to an empty string prior to running the to_number formatting and chokes.
For example select to_number(trim('$1'::text),'FM999999999999D00') will evaluate to 1 but select to_number(trim('$A'::text),'FM999999999999D00') will throw the empty string error.
My fix was to add an additional regex to my initial filter:
and regexp_instr(atl.original_price2,'[0-9]')>0 .
This ensures that at least one number will be in the string and after that the empty string error went away.
Hope my learning experience helps someone else.

Arithmetic operation in jmeter Groovy

I created a script that receives a variable from another sampler.
I put the variable in a new variable (not want to mess with the source).
And I tried to double the result, the problem is that it multiply as a string and not as in math.
The variable is 6, and I wanted to display 12, but it display 6.0 6.0.
Moreover, how can I save the results in a new variable?
System.out.println(" Impression Price *2 is: " + Impression_price*2);
System.out.println(" Impression Price*2 is: " + (Impression_price.multiply(2.0)));
You need to cast your args[3] which is a String to a corresponding numeric type, for example:
def Impression_price = args[3] as float
Demo:
More information: Creating JMeter Variables in Java - The Ultimate Guide
You need to convert String do double using Double.parseDouble, for example:
def Impression_price= Double.parseDouble(args[3]);
When you log you need to convert back to String using String.valueOf, for example:
log.info(String.valueOf(Impression_price*2));
To put a non String value you need to use vars.putObject:
vars.putObject("Impression_price_double", Impression_price *2);

Adding numbers in asp

How do I add the following strings to show the total in asp page?
<%=moviesA%>
<%=moviesB%>
Currently, moviesA = 1000 and moviesB = 400 (both strings are dynamic). I want to display "There are currently 1400 movies in our archives."
Thanks in advance!
To do this you would first add the two numbers and the use Cstr() to change it to a string for writing.
Example:
totalmovies=moviesA+moviesB
response.write ("There are currently " + cstr(totalmovies) + " movies in our archives.")
Note if moviesA and moviesB are Strings already then you need to change them to int before doing the addition then line 1 would be:
totalmovies=cint(moviesA) + cint(moviesB)
Hope it helps.
Thank you both! The cint method did the trick.
The code I ended up using has a slightly different structure...
There are currently
<%totalmovies=cint(moviesA) + cint(moviesB)
response.write (cstr(totalmovies))%>
movies in our archives.
Cheers!

AwesomeWM time not updating?

I'm using AwesomeWM, and I'm trying to display the time in my wibox using this code
vicious.register(datewidget, vicious.widgets.date, os.date("%b ")..(os.date("%d")+0).. ', ' ..(os.date("%I")+0)..os.date(":%M")..string.lower( os.date(" %p ")), 1)
The time is correct when I open AwesomeWM, but it doesn't update. For whatever reason , 1) doesn't work.
heres my full rc.lua
I guess the problem is with what the register function expects. It expects a format string with which it can calculate date itself. Here you're passing a literal string instead of formatting parameters.
From your older question, I found a different method for the same. Now, your vicious need to be like:
vicious.register(datewidget, vicious.widgets.date, "<span font-family='terminus' color='#999999'>%b %d, %l:%M %P</span>", 1)
And it should work.
P.S. Thanks to sa1

Resources