Convertire un valore di tipo Float in una stringa con la funzione PyOS double to string() della libreria libpython3

Da Gambas-it.org - Wikipedia.

La libreria libpython3 è un interfaccia in C di funzioni appartenenti alle risorse di Python.

La funzione "PyOS_double_to_string()" consente di convertire un valore di tipo Float in una stringa.

Per poter fruire in Gambas di tale funzione esterna, è necessario richiamare la libreria condivisa: "libpython3.8.so.1.0 ".

Mostriamo un semplice esempio pratico:

Library "libpython3.8:1.0"

' (char *) PyOS_double_to_string(double val, char format_code, int precision, int flags, int *type)
' Convert a double val to a string using supplied format_code, precision, and flags.
Private Extern PyOS_double_to_string(valf As Float, format_code As Byte, precision As Integer, flags As Integer, type As Pointer) As String


Public Sub Main()

 Dim s As String
 
 s = PyOS_double_to_string(123.456789, CByte(Asc("r")), 0, 0, 0)
 Print s, Len(s)
  
End


Riferimenti