jq 截取指定字符前,如何使用jquery从字符串中获取前4个字母

I am trying to get first 4 digit from string

but its show null

how i mistaken here

What I have tried:alert("Result " + n_result);

//n_result val 1500.02154

lbtot1 = (n_result / 11)

//lbtot1=136.36559454

alert(lbtot1);

var str1 = (n_result / 11);

// str1 val = 136.36559454

alert(str1 + " str1");

var resu1 = str1.substring(0, 4);

alert(resu1);

// here he did not alert any value

//did't show value

// here i want to check is 4th digit/letters/chr (136.) chr is "." or number

解决方案Quote: here i want to check is 4th digit/letters/chr (136.) chr is "." or number

You can't call substring on str1 because it's not a string. But you don't need to - the only way the 4th character will be "." is if the number is greater than or equal to 100, and less than 1000. If n_result could be negative, then numbers greater than -100 and less than or equal to -10 will also have a "." as the 4th character.

var isFouthCharDot = (lbtot1 >= 100 && lbtot1 < 1000) || (lbtot1 > -100 && lbltot1 <= -10);

As a bonus, this will also avoid issues with cultures that use "," as the decimal separator.

jquery is irrelevant here. If you want to convert a number into a string, call str1.toString()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值