|
As a decimal, culture should be irrelevant, and I can't see Sander storing numbers as strings in his DB - that's a rookie mistake.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
It's a decimal going out the db. It's not when it is displayed, or when it is sent back to the database.
Sander Rossel wrote: The input (type="number") shows 1,2 (one comma two), but when I send it to the back-end it's converted to 12.
Even 1.2 (one dot two) is saved as 12.
"Number" might be referring to "ints", not decimals at all.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Eddy Vluggen wrote: "Number" might be referring to "ints", not decimals at all. Because HTML input only knows "number" and not "decimal"
Maybe I should just use an input type="text" and work with a mask.
HTML is as useful as a pair of scissors while running down the stairs.
I'm not even sure which I hate more anymore[^], HTML or CSS.
|
|
|
|
|
Sander Rossel wrote:
HTML is as useful as a pair of scissors while running down the stairs. Wooden stairs, on your socks. With JavaScript-rockets for a small boost.
Since it is a string, again the original question? What culture, and where is it turned back into a real decimal? Or is that "secretly/magically" done by the framwork, a la VB?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
The browser posts a double as "1.2" in JSON (independent of culture I hope) and .NET Core does the deserialization (hopefully also independent of culture).
Even after changing my separator in Windows from comma to dot the deserialization only works with comma.
I'm just baffled that "1.2" is deserialized as 12 and only "1,2" is deserialized as 1.2
|
|
|
|
|
Sander Rossel wrote: The browser posts a double as "1.2" in JSON (independent of culture I hope) and .NET Core does the deserialization (hopefully also independent of culture). You mean it should magically assume the correct one? *
Sander Rossel wrote: Even after changing my separator in Windows from comma to dot the deserialization only works with comma.
I'm just baffled that "1.2" is deserialized as 12 and only "1,2" is deserialized as 1.2 Baffle yourself some more and set it to some non-default character like a question mark. Doing so may break several applications at once, but is usefell during testing.
*) JSON is a string, and has a culture in which the number is expressed/encoded within that string. So it is not a double there. When deserializing, it has to know which culture the client is using.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
FOUND IT!!!
Apparently, I wasn't posting JSON at all...
The entire thing got posted as form data and that uses different deserialization rules for obvious(???) reasons
Changed the type of AJAX to JSON and 1.22 is now serialized as 1.22 (but 1,22 is completely invalid ).
|
|
|
|
|
Deserialized into a decimal again? So an implicit conversion again, hidden?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Yep, now I can't get it to break with an input type="number" (unless I leave it completely empty, but I can validate for that)
|
|
|
|
|
1.22E+0?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I store it in two date fields.
I convert the dates to milliseconds and combine them and with string concatenation place a dot or decimal between them (dependent on culture)
The culture is stored as an array of bits
|
|
|
|
|
What! And miss out on the advantages of storing it in a UNIQUEIDENTIFIER column? Think of the math you could do with 128 bit unsigned fields!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Culture's probably not the problem (if it is it's between browser and back-end, not DB and back-end).
It's posted as string "1.2" (no matter if the separator in the input is actually a comma or dot) and .NET converts that to a whole number.
It's probably a string because it's bound (with Vue.js) to an input and inputs are always strings.
Anyway, you'd think that converting "1.2" to 1.2 before posting would solve the problem.
Unfortunately, it doesn't...
And here I was thinking saving some data was going to be easy
|
|
|
|
|
If it was easy, everybody would do it. You see what happened when we had VB6
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I had a course on a no-code platform last week (Betty Blocks).
The more I code, the more I like no-code
|
|
|
|
|
Sander Rossel wrote: I had a course on a no-code platform last week (Betty Blocks).
The more I code, the more I like no-code Having worked with and on multiple code-generators, I'm a bit sceptical, but looks promising overall. And free to try by the looks of it
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Quote: I'm so happy that after about 30 years of web development I always thought you are very much younger, please correct your Profile picture
It does not solve my Problem, but it answers my question
modified 19-Jan-21 21:04pm.
|
|
|
|
|
I'm 30 actually
Of course I haven't been web developing for 30 years... If I had we wouldn't be in this HTML/CSS/JavaScript mess that is the web today
|
|
|
|
|
I primarily work WPF and that does a great job of converting. However, I recently worked on a project where I had problems with converting number, and so had to do some work arounds. Funny thing was I could not reproduce the problem in a sample project. Go figure.
|
|
|
|
|
Clifford Nelson wrote: Funny thing was I could not reproduce the problem in a sample project Been there, done that. I feel your pain!
|
|
|
|
|
Just tell the user they can't use the number 1.2 or 1,2.
Sander Rossel wrote: Guess I'll just be happy I'm not working with dates.
You're prescience is excellent. Working with date/time in Javascript is such a nightmare. Months are 0-based. Days are 1-based. UTC vs local time. Adding time. Formatting date/time. Ugh. If you haven't already, seriously consider using Moment.js | Home
|
|
|
|
|
Marc Clifton wrote: Just tell the user they can't use the number 1.2 or 1,2. I've considered converting it to an int. It's quite easy for me to use 120 instead of 1.2 or 85 instead of -0.15.
They're sort of "magic" numbers that I got from some calculation I need to use.
I'll gladly divide them by 100 if that means I don't have all that double/decimal trouble in JavaScript and .NET.
Anyway, I figured out what was wrong before I went there
Marc Clifton wrote: seriously consider using Moment.js | Home My go-to library when I need to work with dates (especially when I need to support Klingon culture as well! )
|
|
|
|
|
Sander Rossel wrote: I figured out what was wrong before I went there
Enlighten me. I'm curious.
|
|
|
|
|
It's actually in a post above, but it seems the permalink to posts has disappeared...
Here's a copy/paste (spoiler: I messed up).
Sander Rossel wrote: FOUND IT!!!
Apparently, I wasn't posting JSON at all...
The entire thing got posted as form data and that uses different deserialization rules for obvious(???) reasons
Changed the type of AJAX to JSON and 1.22 is now serialized as 1.22 (but 1,22 is completely invalid ).
|
|
|
|
|
VM with mozilla thunderbird crashed.
I could still get the data but couldn't run any apps (Including thunderbird).
Googled where Thunderbird stores email and email setup.
%appdata%\roaming\thunderbird
Installed Thunderbird on new machine. Did not start it.
Copied %appdata%\roaming\thunderbird from old to new machine.
Started Thunderbird...
All email accounts and email available with no wait and works exactly like it did on the first machine.
Phew...
Very cool, Mozilla.
|
|
|
|