float format decimal places
num = 1.234
print("{:.2f}".format(num))
>> 1.23
print(f"{num:.2f}")
>> 1.23
float format decimal places
num = 1.234
print("{:.2f}".format(num))
>> 1.23
print(f"{num:.2f}")
>> 1.23
converting float to binary 16
import struct
#################### bin32 ################################
# import bitstring
# f1 = bitstring.BitArray(float=0.456789, length=32)
# # f1 = bitstring.BitArray(float=0.456789, length=16)
# print(f1.bin)
# print("0011011101001111")
#################### bin32 ################################
def convertFloatToBin16(x):
k = struct.pack('>e', x)
z = ''.join(format(i, '08b') for i in k)
return str(z)
print(convertFloatToBin16(0.9945678))
c float to int
# you can cast in c like so
float my_float= 1.446;
int my_int = (int) my_float;
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us