flat assembler
Message board for the users of flat assembler.
Index
> Windows > Fasm and Mysql |
Author |
|
revolution 03 Nov 2015, 00:23
So if I read the correctly, all you need is a way to print floats into ASCII text? If so the import msvcrt.dll and use the sprintf (or equivalent) function.
|
|||
03 Nov 2015, 00:23 |
|
ProphetOfDoom 03 Nov 2015, 11:14
Clamicun,
I don't know the answer to your question, but in any case it's not a good idea to use floats or doubles to represent currency. This stack overflow answer explains why (basically, currency requires exactness, which floats don't provide): http://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency |
|||
03 Nov 2015, 11:14 |
|
clamicun 03 Nov 2015, 14:11
revolution thank you,
well - what I want to do first is convert a string from a dialogbox input into a float. I know that there is a function atof in msvcrt. But where is msvcrt ? My fasmversion - surprisingly - does not have it. So I am using msvcrt.inc from MASM. Should be same ?? teststr db "12.53",0 (c)invoke atof,teststr ;is this the correct syntax ? The result should be where - eax ? Does not work ! What is this locale business ? My german system uses , insteadof . If you please, write an example, which works. |
|||
03 Nov 2015, 14:11 |
|
l_inc 03 Nov 2015, 15:16
clamicun
If you aren't after implementing the db communication protocol from scratch, you're gonna need a library such as this one. And when you have your choice met, then the library defines for you what format it needs the numbers to be passed (see here for libsqlclient). I wouldn't suggest you to use msvcrt, because a library as the one above might not need the numbers in a textual representation. You'd just reference your number in a bind structure before calling mysql_stmt_bind_param . The way you stored the number with mov [value1],-45.33 is perfectly valid for single precision floatings. Quote: So I am using msvcrt.inc from MASM. Should be same ?? msvcrt.inc from masm has nothing to do with the way fasm declares imports. Just specify the functions you need with the library and import macros the same way you did it in the first post. You don't need a separate inc-file for that. Quote: teststr db "12.53",0 You initially wanted to convert floats to string. What does atof have to do with that? As revolution suggested you could use sprintf . _________________ Faith is a superposition of knowledge and fallacy |
|||
03 Nov 2015, 15:16 |
|
clamicun 03 Nov 2015, 15:32
L_inc,
everybody is not going to understand me - why ? Are we talking a different language ? I did NOT want initially to convert floats to string !! This is what I wrote above...beginning of this page... "The input 'value' comes from a dialogbox (dialogitem EDIT). it is a string, that somehow must be converted into a float ??" |
|||
03 Nov 2015, 15:32 |
|
clamicun 03 Nov 2015, 15:39
P.S. to L_inc
What are you talking ? I did not mention mysql problems. I am talking on Fasm instead of php and mysql. I am writing websites since 2001 |
|||
03 Nov 2015, 15:39 |
|
l_inc 03 Nov 2015, 15:56
clamicun
Well, sorry I misinterpreted what was your primary objective. All your code samples you've shown you had problems with were related to wsprintf . Hence the misunderstanding. Quote: teststr db "12.53",0 Yes. It is. You need cinvoke . Quote: The result should be where - eax ? The result should be in st0 , which is then possible to extract into a memory location using fstp qword[buffer] . Quote: What is this locale business ? My german system uses , insteadof . Yes, so what's the problem? Quote: What are you talking ? I did not mention mysql problems. I though, you were talking about replacing php with asm. In order to do that you need an interface library for your mysql db. _________________ Faith is a superposition of knowledge and fallacy |
|||
03 Nov 2015, 15:56 |
|
clamicun 03 Nov 2015, 16:23
L_inc thank you,
I wrote (c)invoke because I tested the two possibilities. None worked. What do you mean " st0 " ? Is it the below buffer ? My error was that I thought the result would be in eax ? Then... fstp qword[buffer] ??? The locale business is important. Try getting 12,44 into an american database. P.S. php is much easier |
|||
03 Nov 2015, 16:23 |
|
l_inc 03 Nov 2015, 17:13
clamicun
Quote: What do you mean " st0 " ? Is it the below buffer ? st0 is one of the eight FPU (floating point unit, part of the CPU) registers logically organized in a stack (not to confuse with the program stack). If you want to deal with floating point numbers it's absolutely necessary for you to find a tutorial on the x87 FPU programming and to use the Intel Manuals as a reference. Quote: Then... Please try to compose your questions more complete. fstp is an FPU instruction that pops a value from the FPU stack. Quote: The locale business is important. I know it is. But you didn't describe your problem. Try to be more specific in your questions, if you don't like misunderstandings. What are you trying to achieve? Use arbitrary locales? You can use then setlocale or _create_locale / _free_locale with LC_NUMERIC . _________________ Faith is a superposition of knowledge and fallacy |
|||
03 Nov 2015, 17:13 |
|
clamicun 03 Nov 2015, 19:49
Ok L_inc,
thank you a lot. But.... Do not try to "educate" people in this bloody arrogant way ! (Are you from the US ?) "What do you mean "st0 " ... is a perfectly complete question " Your answer: "st0 is one of the eight FPU (floati.... " ... is a perfectly clear answer. But spare me things like: "Please try to compose your questions more complete" "Try to be more specific in your questions" Good evening clamicun |
|||
03 Nov 2015, 19:49 |
|
l_inc 03 Nov 2015, 20:46
clamicun
Nein, ich bin sehr bescheiden und komme aus dem gleichen Staat wie Sie. Was Ihre Fragen und meine Belehrungen angeht, da, wo ich problemlos antworten konnte, habe ich auch nicht kommentiert. Wo Sie aber nur sinnlose Fragezeichen gesetzt haben, ohne sich die Mühe zu geben, die Frage sinnvoll zu formulieren, musste ich nur raten, worum es geht. Und möglicherweise auch falsch. Im Zusammenhang von ausschließlich string to float Umrechnung macht zum Beispiel die Diskussion über konfigurierbare Lokale keinen Sinn, da die Zahlen an die Datenbank im lokalunabhängigen Format weitergereicht werden. Quote: But spare me things like: Durch Ihre Frage: "Are we talking a different language?" — haben Sie selber gezeigt, dass Sie die Erklarung für Missverständnisse brauchen. _________________ Faith is a superposition of knowledge and fallacy |
|||
03 Nov 2015, 20:46 |
|
typedef 05 Nov 2015, 22:26
Don't use floating numbers for saving currency. Instead convert them to the lowest unit of your currency.
For instance US $24.75 * 100 = 2475 Cents. Store 2475 into the database as long. Then when querying you can use a function to get the integer and floating part. Code: void getCurrency(unsigned long value, int * dollars, int * cents) { *dollars = value / 100; *cents = value MOD 100; } long money = 2475; int dollars, cents; wchar_t pszMoney[100] = {0}; getCurrency(money, &dollars, ¢s); wsprintfW(pszMoney, "$ %d.%.02d", dollars, cents); SetWindowTextW(hwndTextMoney, pszMoney); |
|||
05 Nov 2015, 22:26 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.