TextFloatMethods (C++)
Description
This example reads a floating-point value as a string and calls the TextToFloat method that will convert the number to a floating-point value. Then, you modify the decimal separator and call the FloatToText method to convert the floating-point value to a string that will be further displayed.
Code
int _tmain(int argc, _TCHAR* argv[])
{
wchar_t text[100];
double number;
/* Read the floating-point value as a string. */
printf("Enter a floating point number: "); scanf("%ls", text);
/* Call the TextToFloat method to convert the string value to a double. */
TextToFloat(text, &number, fvExtended);
/* Output the results to the console. */
printf("The number with the standard decimal separator is: %ls\n", text);
/* Now modify the separator character. */
Sysutils::DecimalSeparator = ',';
/* Call FloatToText with the value passed as an Extended, with precision 15.
The result of the call is the number of characters actually set in the buffer
(text). */
FloatToText(text, &number, fvExtended, ffGeneral, 15, 0);
/* Output the results to the console. */
printf("The number with the modified decimal separator is: %ls\n", text);
return 0;
}
Uses
- System.SysUtils.FloatToText ( fr | de | ja )
- System.SysUtils.TextToFloat ( fr | de | ja )
- System.SysUtils.TFormatSettings.DecimalSeparator ( fr | de | ja )