formatting numbers

  • Thread starter Thread starter Highpotech IT
  • Start date Start date
H

Highpotech IT

i'am using the following statement to format a aql string
sql=string.format("INSERT INTO werkboek VALUES {0}, {1}....;"
m_WNR, m_Aantal...)
Aantal is a decimal and evaluates into 2.5D. Evalutating the sql strin
i get:
"INSERT INTO werkboek VALUES 7, 2,5....;"
I've changed te code for the placeholder {1} to {1:#.00} in order to
change te output to 2.5 instead of 2,5 but no luck.
Is there a other way to change ste code to get te requered output te
read:
"INSERT INTO werkboek VALUES 7, 2.5....;"

Thanks in advance
Alexander M. Polak
mailto:[email protected]
 
Highpotech IT said:
i'am using the following statement to format a aql string
sql=string.format("INSERT INTO werkboek VALUES {0}, {1}....;"
m_WNR, m_Aantal...)
Aantal is a decimal and evaluates into 2.5D. Evalutating the sql strin
i get:
"INSERT INTO werkboek VALUES 7, 2,5....;"
I've changed te code for the placeholder {1} to {1:#.00} in order to
change te output to 2.5 instead of 2,5 but no luck.
Is there a other way to change ste code to get te requered output te
read:
"INSERT INTO werkboek VALUES 7, 2.5....;"

Rather than formatting the values, use parameters instead.

See http://www.pobox.com/~skeet/csharp/faq/#db.parameters
 
Tanks.
Using parems creates a new problem the one i wantted to avoid. So your
suggestion is no answer to the quistion at hand
 
Rather then using an other approch I'like to use the one i want and to
solve the problem at hand.

Tanks anyway
 
Alexander M. Polak said:
Using parems creates a new problem the one i wantted to avoid. So your
suggestion is no answer to the quistion at hand

Well, I'd suggest that using parameters is still likely to be a better
solution, even if you then have to solve other problems - embedding
literals in SQL statements comes with all kinds of problems. (SQL
injection attacks, determining the input format for things like dates,
numbers etc, performance, to name just a few.)

However, if you specify CultureInfo.InvariantCulture before your format
string, I think that will solve your immediate problem.
 
Back
Top