update trouble 3

Documentation Version for Comments and Changes

You are invited to make any changes...add any comments.

Changes will `eventually` be merged into the offical documentation.

Leave any commnents here...


... back to index page OE documentation

might have a tiny bit of error in the result. Sometimes you can solve the problem by rounding, e.g. x = round( x, 100 ) would round x off to the nearest hundredth. Storing money values as an integer number of pennies, rather than a fractional number of dollars (or similar currency) will help, but some calculations could still cause problems.

Number to a string?

How do I convert a number to a string?

Use sprintf:

string = eu:sprintf("%d", 10) -- string is "10" 

or use number:

include std/locale.e as locale 
string = locale:number(10)  
         -- string is probably "10.00" if called in the U.S. 
         -- It depends on the locale preferences set on your computer. 

Number formats according to the locale setting on your computer and strangely, this means to give you two decimal places whether or not you supply an integer value for the U.S. locale.

Besides %d, you can also try other formats, such as %x (Hex) or %f (floating-point).

String to a number?

How do I convert a string to a number?

Use value.

Redefine my for-loop variable?

It says I'm attempting to redefine my for-loop variable.

For-loop variables are declared automatically. Apparently you already have a declaration with the same name earlier in your routine or your program. Remove that earlier declaration or change the name of your loop variable.

Unknown Escape Character

I get the message "unknown escape character" on a line where I am trying to specify a file name.

Do not say "C:\TMP\MYFILE". You need to say "C:\\TMP\\MYFILE" or use back-quotes `C:\TMP\MYFILE`.

Backslash is used for escape characters such as \n or \t. To specify a single backslash in a string you need to type \\. Therefore, say "C:\\TMP\\MYFILE" instead of "C:\TMP\MYFILE"

Only first character in printf

I'm trying to print a string using printf but only the first character comes out.

You need to put braces around the parameters sequence to printf. You probably wrote:

printf(1, "Hello, %s!\n", mystring)
Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu