StrD round problem

Just starting out? Need help? Post your questions and find answers here.
mx101
User
User
Posts: 73
Joined: Thu Sep 18, 2008 3:21 pm

StrD round problem

Post by mx101 »

hi again...

i have a problem when i convert a double number to string.


here is an example:


i have


dH.d = 23.976

dT.d = dH.d *1

SetGadgetText(1, StrD(dT.d), 2)

always show as result 23.98

but i whant show 23.976*1= 23.976

I don't want to round this number

anyone can help me
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: StrD round problem

Post by STARGÅTE »

:?: :?:

Code: Select all

dH.d = 23.976
dT.d = dH.d *1
Debug StrD(dT)
note:

Code: Select all

dH.d = 23.976
dT.d = dH.d *1
Debug StrD(dT,2)
bug in your code ?
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: StrD round problem

Post by netmaestro »

Supply 3 for the NbDecimals parameter of StrD():

Code: Select all

dH.d = 23.976
dT.d = dH.d *1

OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
TextGadget(1,10,10,200,20,"")
SetGadgetText(1, StrD(dT.d, 3))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
BERESHEIT
mx101
User
User
Posts: 73
Joined: Thu Sep 18, 2008 3:21 pm

Re: StrD round problem

Post by mx101 »

netmaestro wrote:Supply 3 for the NbDecimals parameter of StrD():

Code: Select all

dH.d = 23.976
dT.d = dH.d *1

OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
TextGadget(1,10,10,200,20,"")
SetGadgetText(1, StrD(dT.d, 3))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
you are right when Supply 3 show the correct result.

if supply only 2 round up result.


thanks :)
Post Reply