Gets the name of a number, even if it's stupidly big. Supersedes TheoryOfNekomata/number-name.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

76 行
1.9 KiB

  1. import { describe, it, expect } from 'vitest';
  2. import { exponentialToNumberString, numberToExponential } from '../src/exponent';
  3. describe('numberToExponential', () => {
  4. it('converts 0 to 0e+0', () => {
  5. expect(numberToExponential(0)).toBe('0e+0');
  6. });
  7. it('converts "0" to 0e+0', () => {
  8. expect(numberToExponential('0')).toBe('0e+0');
  9. });
  10. it('converts "00000000000000000" to 0e+0', () => {
  11. expect(numberToExponential('00000000000000000')).toBe('0e+0');
  12. });
  13. it('converts 1 to 1e+0', () => {
  14. expect(numberToExponential(1)).toBe('1e+0');
  15. });
  16. it('converts "0.1" to 1e-1', () => {
  17. expect(numberToExponential('0.1')).toBe('1e-1');
  18. });
  19. it('converts "0.10" to 1e-1', () => {
  20. expect(numberToExponential('0.10')).toBe('1e-1');
  21. });
  22. it('converts "1" to 1e+0', () => {
  23. expect(numberToExponential('1')).toBe('1e+0');
  24. });
  25. it('converts "10" to 1e+1', () => {
  26. expect(numberToExponential('10')).toBe('1e+1');
  27. });
  28. it('converts "100" to 1e+2', () => {
  29. expect(numberToExponential('100')).toBe('1e+2');
  30. });
  31. it('converts "0100" to 1e+2', () => {
  32. expect(numberToExponential('0100')).toBe('1e+2');
  33. });
  34. it('converts "1234567890" to 1.23456789e+9', () => {
  35. expect(numberToExponential('1234567890')).toBe('1.23456789e+9');
  36. });
  37. it('converts "1234567890.1234567890" to 1.234567890123456789e+9', () => {
  38. expect(numberToExponential('1234567890.1234567890')).toBe('1.234567890123456789e+9');
  39. });
  40. it('converts "1e+100" to 1e+100', () => {
  41. expect(numberToExponential('1e+100')).toBe('1e+100');
  42. });
  43. it('converts "12.3e+10" to 1.23e+11', () => {
  44. expect(numberToExponential('12.3e+10')).toBe('1.23e+11');
  45. });
  46. });
  47. describe('exponentialToNumberString', () => {
  48. it('converts 1e+0 to 1', () => {
  49. expect(exponentialToNumberString('1e+0')).toBe('1');
  50. });
  51. it('converts 1e+1 to 10', () => {
  52. expect(exponentialToNumberString('1e+1')).toBe('10');
  53. });
  54. it('converts 1.23e+1 to 12.3', () => {
  55. expect(exponentialToNumberString('1.23e+1')).toBe('12.3');
  56. });
  57. });