Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.5 KiB

  1. #ifndef _CRTBLD
  2. #define _CRTBLD
  3. #endif
  4. #include <windows.h>
  5. #include <shlwapi.h>
  6. /***
  7. * double StrToDbl(const char *str, char **strStop) - convert string to double
  8. *
  9. * Purpose:
  10. * To convert a string into a double. This function supports
  11. * simple double representations like '1.234', '.5678'. It also support
  12. * the a killobyte computaion by appending 'k' to the end of the string
  13. * as in '1.5k' or '.5k'. The results would then become 1536 and 512.5.
  14. *
  15. * Return:
  16. * The double representation of the string.
  17. * strStop points to the character that caused the scan to stop.
  18. *
  19. *******************************************************************************/
  20. double __cdecl StrToDbl(const char *str, char **strStop)
  21. {
  22. double dbl = 0;
  23. char *psz;
  24. int iMult = 1;
  25. int iKB = 1;
  26. int iVal = 0;
  27. BOOL bHaveDot = FALSE;
  28. psz = (char*)str;
  29. while(*psz)
  30. {
  31. if((*psz >= '0') && (*psz <= '9'))
  32. {
  33. iVal = (iVal * 10) + (*psz - '0');
  34. if(bHaveDot)
  35. iMult *= 10;
  36. }
  37. else if((*psz == '.') && !bHaveDot)
  38. {
  39. bHaveDot = TRUE;
  40. }
  41. else if((*psz == 'k') || (*psz == 'K'))
  42. {
  43. iKB = 1024;
  44. psz++;
  45. break;
  46. }
  47. else
  48. {
  49. break;
  50. }
  51. psz++;
  52. }
  53. *strStop = psz;
  54. dbl = (double) (iVal * iKB) / iMult;
  55. return(dbl);
  56. }