Core Function FHex

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
Line 28: Line 28:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$lol = (float)1337.42
+
$lol = (float)1337.42;
$fHex = fHex($lol)
+
$fHex = fHex($lol);
$fDec = fDec($fHex)
+
$fDec = fDec($fHex);
println( "FLOAT HEX: " . $fHex ) ; Prints 44A72D71
+
println( "FLOAT HEX: " . $fHex ); // Prints 44A72D71
println( "FLOAT DEC: " . $fDec ) ; Prints 1337.42004394531
+
println( "FLOAT DEC: " . $fDec ); // Prints 1337.42004394531
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 38: Line 38:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$var = 1337.77
+
$var = 1337.77;
$fHex = fHex((float)$var)
+
$fHex = fHex((float)$var);
$fDec = fDec($fHex)
+
$fDec = fDec($fHex);
println( "FLOAT HEX: " . $fHex ) ; Prints 44A72D71
+
println( "FLOAT HEX: " . $fHex ); // Prints 44A72D71
println( "FLOAT DEC: " . $fDec ) ; Prints 1337.42004394531
+
println( "FLOAT DEC: " . $fDec ); // Prints 1337.42004394531
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Revision as of 21:01, 18 November 2011

FHex( <expression> )

Contents

Description

Returns a string representation of an float type converted to hexadecimal.

Parameters

expression

The expression to convert.

Return Value

Success: Returns a string of length characters, zero-padded if necessary for integer.

Failure: Returns "" (blank string).

Remarks

The function only works with numbers that fit in a 32 bit signed floating point.

It is best to cast numbers with (float) to make sure its going to be a float.

Example

$lol = (float)1337.42;
$fHex = fHex($lol);
$fDec = fDec($fHex);
println( "FLOAT HEX: " . $fHex ); // Prints 44A72D71
println( "FLOAT DEC: " . $fDec ); // Prints 1337.42004394531

Example with cast on a $variable

$var = 1337.77;
$fHex = fHex((float)$var);
$fDec = fDec($fHex);
println( "FLOAT HEX: " . $fHex ); // Prints 44A72D71
println( "FLOAT DEC: " . $fDec ); // Prints 1337.42004394531
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox